private static NlsString asUnicodeString(String text) { return new NlsString(text, ConversionUtil.NATIVE_UTF16_CHARSET_NAME, SqlCollation.IMPLICIT); }
private static NlsString asUnicodeString(String text) { return new NlsString(text, ConversionUtil.NATIVE_UTF16_CHARSET_NAME, SqlCollation.IMPLICIT); }
/** Creates a copy of this {@code NlsString} with different content but same * charset and collation. */ public NlsString copy(String value) { return new NlsString(value, charsetName, collation); }
/** Creates a copy of this {@code NlsString} with different content but same * charset and collation. */ public NlsString copy(String value) { return new NlsString(value, charsetName, collation); } }
/** * Returns a string the same as this but with spaces trimmed from the * right. */ public NlsString rtrim() { String trimmed = SqlFunctions.rtrim(value); if (!trimmed.equals(value)) { return new NlsString(trimmed, charsetName, collation); } return this; }
/** * Creates a string literal, with optional character-set. * * @param s a string (without the sql single quotes) * @param charSet character set name, null means take system default * @param pos Parser position * @return A string literal * @throws UnsupportedCharsetException if charSet is not null but there is * no character set with that name in this * environment */ public static SqlCharStringLiteral createCharString( String s, String charSet, SqlParserPos pos) { NlsString slit = new NlsString(s, charSet, null); return new SqlCharStringLiteral(slit, pos); }
/** * Creates a string literal, with optional character-set. * * @param s a string (without the sql single quotes) * @param charSet character set name, null means take system default * @param pos Parser position * @return A string literal * @throws UnsupportedCharsetException if charSet is not null but there is * no character set with that name in this * environment */ public static SqlCharStringLiteral createCharString( String s, String charSet, SqlParserPos pos) { NlsString slit = new NlsString(s, charSet, null); return new SqlCharStringLiteral(slit, pos); }
/** * Creates a character string literal with type CHAR and default charset and * collation. * * @param s String value * @return Character string literal */ protected RexLiteral makePreciseStringLiteral(String s) { assert s != null; if (s.equals("")) { return charEmpty; } else { return makeLiteral( new NlsString(s, null, null), typeFactory.createSqlType( SqlTypeName.CHAR, s.length()), SqlTypeName.CHAR); } }
/** * Creates a character string literal with type CHAR and default charset and * collation. * * @param s String value * @return Character string literal */ protected RexLiteral makePreciseStringLiteral(String s) { assert s != null; if (s.equals("")) { return charEmpty; } else { return makeLiteral( new NlsString(s, null, null), typeFactory.createSqlType( SqlTypeName.CHAR, s.length()), SqlTypeName.CHAR); } }
/** * Returns a string the same as this but with spaces trimmed from the * right. */ public NlsString rtrim() { String trimmed = SqlFunctions.rtrim(getValue()); if (!trimmed.equals(getValue())) { return new NlsString(trimmed, charsetName, collation); } return this; }
/** * Creates a character string literal with type CHAR. * * @param value String value in bytes * @param charsetName SQL-level charset name * @param collation Sql collation * @return String literal */ protected RexLiteral makePreciseStringLiteral(ByteString value, String charsetName, SqlCollation collation) { return makeLiteral( new NlsString(value, charsetName, collation), typeFactory.createSqlType(SqlTypeName.CHAR), SqlTypeName.CHAR); }
public RexLiteral charLiteral(String z) { return rexBuilder.makeCharLiteral( new NlsString(z, null, SqlCollation.COERCIBLE)); }
public RexLiteral charLiteral(String z) { return rexBuilder.makeCharLiteral( new NlsString(z, null, SqlCollation.COERCIBLE)); }
@Test public void testNlsStringClone() { final NlsString s = new NlsString("foo", "LATIN1", SqlCollation.IMPLICIT); assertThat(s.toString(), is("_LATIN1'foo'")); final Object s2 = s.clone(); assertThat(s2, instanceOf(NlsString.class)); assertThat(s2, not(sameInstance((Object) s))); assertThat(s2.toString(), is(s.toString())); }
@Test public void testNlsStringClone() { final NlsString s = new NlsString("foo", "LATIN1", SqlCollation.IMPLICIT); assertThat(s.toString(), is("_LATIN1'foo'")); final Object s2 = s.clone(); assertThat(s2, instanceOf(NlsString.class)); assertThat(s2, not(sameInstance((Object) s))); assertThat(s2.toString(), is(s.toString())); }
@Test public void testSubstring() throws Exception { check((rexBuilder, executor) -> { final List<RexNode> reducedValues = new ArrayList<>(); final RexLiteral hello = rexBuilder.makeCharLiteral( new NlsString("Hello world!", null, null)); final RexNode plus = rexBuilder.makeCall(SqlStdOperatorTable.PLUS, rexBuilder.makeExactLiteral(BigDecimal.ONE), rexBuilder.makeExactLiteral(BigDecimal.ONE)); RexLiteral four = rexBuilder.makeExactLiteral(BigDecimal.valueOf(4)); final RexNode substring = rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, hello, plus, four); executor.reduce(rexBuilder, ImmutableList.of(substring, plus), reducedValues); assertThat(reducedValues.size(), equalTo(2)); assertThat(reducedValues.get(0), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(0)).getValue2(), equalTo((Object) "ello")); // substring('Hello world!, 2, 4) assertThat(reducedValues.get(1), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(1)).getValue2(), equalTo((Object) 2L)); }); }
@Test public void testSubstring() throws Exception { check((rexBuilder, executor) -> { final List<RexNode> reducedValues = new ArrayList<>(); final RexLiteral hello = rexBuilder.makeCharLiteral( new NlsString("Hello world!", null, null)); final RexNode plus = rexBuilder.makeCall(SqlStdOperatorTable.PLUS, rexBuilder.makeExactLiteral(BigDecimal.ONE), rexBuilder.makeExactLiteral(BigDecimal.ONE)); RexLiteral four = rexBuilder.makeExactLiteral(BigDecimal.valueOf(4)); final RexNode substring = rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, hello, plus, four); executor.reduce(rexBuilder, ImmutableList.of(substring, plus), reducedValues); assertThat(reducedValues.size(), equalTo(2)); assertThat(reducedValues.get(0), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(0)).getValue2(), equalTo((Object) "ello")); // substring('Hello world!, 2, 4) assertThat(reducedValues.get(1), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(1)).getValue2(), equalTo((Object) 2L)); }); }
/** * Creates a RexBuilder. * * @param typeFactory Type factory */ public RexBuilder(RelDataTypeFactory typeFactory) { this.typeFactory = typeFactory; this.booleanTrue = makeLiteral( Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN); this.booleanFalse = makeLiteral( Boolean.FALSE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN); this.charEmpty = makeLiteral( new NlsString("", null, null), typeFactory.createSqlType(SqlTypeName.CHAR, 0), SqlTypeName.CHAR); this.constantNull = makeLiteral( null, typeFactory.createSqlType(SqlTypeName.NULL), SqlTypeName.NULL); }
/** * Creates a RexBuilder. * * @param typeFactory Type factory */ public RexBuilder(RelDataTypeFactory typeFactory) { this.typeFactory = typeFactory; this.booleanTrue = makeLiteral( Boolean.TRUE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN); this.booleanFalse = makeLiteral( Boolean.FALSE, typeFactory.createSqlType(SqlTypeName.BOOLEAN), SqlTypeName.BOOLEAN); this.charEmpty = makeLiteral( new NlsString("", null, null), typeFactory.createSqlType(SqlTypeName.CHAR, 0), SqlTypeName.CHAR); this.constantNull = makeLiteral( null, typeFactory.createSqlType(SqlTypeName.NULL), SqlTypeName.NULL); }