private Expression createEmptyColumnStatsRow(String columnName) { ImmutableList.Builder<Expression> rowValues = ImmutableList.builder(); rowValues.add(new StringLiteral(columnName)); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_VARCHAR); rowValues.add(NULL_VARCHAR); return new Row(rowValues.build()); }
@Override public Node visitUnicodeStringLiteral(SqlBaseParser.UnicodeStringLiteralContext context) { return new StringLiteral(getLocation(context), decodeUnicodeLiteral(context)); }
private Row createColumnStatsRow(String columnName, Type type, ColumnStatistics columnStatistics) { ImmutableList.Builder<Expression> rowValues = ImmutableList.builder(); rowValues.add(new StringLiteral(columnName)); rowValues.add(createEstimateRepresentation(columnStatistics.getDataSize())); rowValues.add(createEstimateRepresentation(columnStatistics.getDistinctValuesCount())); rowValues.add(createEstimateRepresentation(columnStatistics.getNullsFraction())); rowValues.add(NULL_DOUBLE); rowValues.add(toStringLiteral(type, columnStatistics.getRange().map(DoubleRange::getMin))); rowValues.add(toStringLiteral(type, columnStatistics.getRange().map(DoubleRange::getMax))); return new Row(rowValues.build()); }
@Test public void testSetSession() { testSetSession(new StringLiteral("baz"), "baz"); testSetSession(new FunctionCall(QualifiedName.of("concat"), ImmutableList.of( new StringLiteral("ban"), new StringLiteral("ana"))), "banana"); }
@Test public void testSetSession() { testSetSession(new StringLiteral("baz"), "baz"); testSetSession(new FunctionCall(QualifiedName.of("concat"), ImmutableList.of( new StringLiteral("ban"), new StringLiteral("ana"))), "banana"); }
private static StringLiteral rawStringLiteral(final Slice slice) { return new StringLiteral(slice.toStringUtf8()) { @Override public Slice getSlice() { return slice; } }; }
@Test public void testGetChildren() { StringLiteral value = new StringLiteral("a"); StringLiteral pattern = new StringLiteral("b"); StringLiteral escape = new StringLiteral("c"); assertEquals(new LikePredicate(value, pattern, escape).getChildren(), ImmutableList.of(value, pattern, escape)); assertEquals(new LikePredicate(value, pattern, Optional.empty()).getChildren(), ImmutableList.of(value, pattern)); } }
@Test public void testSetSession() { assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar"))); assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz"))); assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz"))); assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession( QualifiedName.of("foo", "bar"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of( new StringLiteral("ban"), new StringLiteral("ana"))))); }
private static Expression createFailureFunction(RuntimeException exception, Type type) { requireNonNull(exception, "Exception is null"); String failureInfo = JsonCodec.jsonCodec(FailureInfo.class).toJson(Failures.toFailure(exception).toFailureInfo()); FunctionCall jsonParse = new FunctionCall(QualifiedName.of("json_parse"), ImmutableList.of(new StringLiteral(failureInfo))); FunctionCall failureFunction = new FunctionCall(QualifiedName.of("fail"), ImmutableList.of(jsonParse)); return new Cast(failureFunction, type.getTypeSignature().toString()); }
@Test public void testSetSessionWithParameters() { List<Expression> expressionList = new ArrayList<>(); expressionList.add(new StringLiteral("ban")); expressionList.add(new Parameter(0)); testSetSessionWithParameters("bar", new FunctionCall(QualifiedName.of("concat"), expressionList), "banana", ImmutableList.of(new StringLiteral("ana"))); }
@Test public void testSetSessionWithParameters() { List<Expression> expressionList = new ArrayList<>(); expressionList.add(new StringLiteral("ban")); expressionList.add(new Parameter(0)); testSetSessionWithParameters("bar", new FunctionCall(QualifiedName.of("concat"), expressionList), "banana", ImmutableList.of(new StringLiteral("ana"))); }
@Override public Node visitBasicStringLiteral(SqlBaseParser.BasicStringLiteralContext context) { return new StringLiteral(getLocation(context), unquote(context.STRING().getText())); }
@Override public Node visitBasicStringLiteral(SqlBaseParser.BasicStringLiteralContext context) { return new StringLiteral(getLocation(context), unquote(context.STRING().getText())); }
private static void assertLike(byte[] value, String pattern, boolean expected) { Expression predicate = new LikePredicate( rawStringLiteral(Slices.wrappedBuffer(value)), new StringLiteral(pattern), Optional.empty()); assertEquals(evaluate(predicate), expected); }
public static Query singleValueQuery(String columnName, String value) { Relation values = values(row(new StringLiteral((value)))); return simpleQuery( selectList(new AllColumns()), aliased(values, "t", ImmutableList.of(columnName))); }
private static void assertLike(byte[] value, String pattern, boolean expected) { Expression predicate = new LikePredicate( rawStringLiteral(Slices.wrappedBuffer(value)), new StringLiteral(pattern), Optional.empty()); assertEquals(evaluate(predicate), expected); }
private static Row createDescribeInputRow(Parameter parameter, Analysis queryAnalysis) { Type type = queryAnalysis.getCoercion(parameter); if (type == null) { type = UNKNOWN; } return row( new LongLiteral(Integer.toString(parameter.getPosition())), new StringLiteral(type.getTypeSignature().getBase())); }
private static Row createDescribeInputRow(Parameter parameter, Analysis queryAnalysis) { Type type = queryAnalysis.getCoercion(parameter); if (type == null) { type = UNKNOWN; } return row( new LongLiteral(Integer.toString(parameter.getPosition())), new StringLiteral(type.getTypeSignature().getBase())); }
@Test public void testArrayConstructor() { assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of())); assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2")))); assertExpression("ARRAY [1e0, 2.5e0]", new ArrayConstructor(ImmutableList.of(new DoubleLiteral("1.0"), new DoubleLiteral("2.5")))); assertExpression("ARRAY ['hi']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi")))); assertExpression("ARRAY ['hi', 'hello']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"), new StringLiteral("hello")))); }
@Test public void testCall() { assertStatement("CALL foo()", new Call(QualifiedName.of("foo"), ImmutableList.of())); assertStatement("CALL foo(123, a => 1, b => 'go', 456)", new Call(QualifiedName.of("foo"), ImmutableList.of( new CallArgument(new LongLiteral("123")), new CallArgument("a", new LongLiteral("1")), new CallArgument("b", new StringLiteral("go")), new CallArgument(new LongLiteral("456"))))); }