use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldEscapeQuotesInStringLiteralQuote.
@Test
public void shouldEscapeQuotesInStringLiteralQuote() {
// Given:
final Expression expression = new StringLiteral("\\\"");
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("\"\\\\\\\"\""));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldPostfixFunctionInstancesWithUniqueId.
@Test
public void shouldPostfixFunctionInstancesWithUniqueId() {
// Given:
final UdfFactory ssFactory = mock(UdfFactory.class);
final KsqlScalarFunction ssFunction = mock(KsqlScalarFunction.class);
final UdfFactory catFactory = mock(UdfFactory.class);
final KsqlScalarFunction catFunction = mock(KsqlScalarFunction.class);
givenUdf("SUBSTRING", ssFactory, ssFunction, SqlTypes.STRING);
when(ssFunction.parameters()).thenReturn(ImmutableList.of(ParamTypes.STRING, ParamTypes.INTEGER, ParamTypes.INTEGER));
givenUdf("CONCAT", catFactory, catFunction, SqlTypes.STRING);
when(catFunction.parameters()).thenReturn(ImmutableList.of(ParamTypes.STRING, ParamTypes.STRING));
final FunctionName ssName = FunctionName.of("SUBSTRING");
final FunctionName catName = FunctionName.of("CONCAT");
final FunctionCall substring1 = new FunctionCall(ssName, ImmutableList.of(COL1, new IntegerLiteral(1), new IntegerLiteral(3)));
final FunctionCall substring2 = new FunctionCall(ssName, ImmutableList.of(COL1, new IntegerLiteral(4), new IntegerLiteral(5)));
final FunctionCall concat = new FunctionCall(catName, ImmutableList.of(new StringLiteral("-"), substring2));
final Expression expression = new FunctionCall(catName, ImmutableList.of(substring1, concat));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, is("((String) CONCAT_0.evaluate(" + "((String) SUBSTRING_1.evaluate(COL1, 1, 3)), " + "((String) CONCAT_2.evaluate(\"-\"," + " ((String) SUBSTRING_3.evaluate(COL1, 4, 5))))))"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldAppendNewKeyColumnsToValueIfPartitioningByMixOfColumnsAndExpressions.
@Test
public void shouldAppendNewKeyColumnsToValueIfPartitioningByMixOfColumnsAndExpressions() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")), new UnqualifiedColumnReferenceExp(COL1), new FunctionCall(CONSTANT_UDF_NAME, ImmutableList.of(new UnqualifiedColumnReferenceExp(COL1))))).getMapper();
final ImmutableList<Object> originals = ImmutableList.copyOf(value.values());
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
// Then:
assertThat(result.value, is(GenericRow.fromList(originals).append(OLD_KEY + "-foo").append(ConstantUdf.VALUE)));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByMixOfKeyAndNonKeyExpressions.
@Test
public void shouldPropagateNullValueWhenPartitioningByMixOfKeyAndNonKeyExpressions() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")), new UnqualifiedColumnReferenceExp(COL1))).getMapper();
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, null);
// Then:
assertThat(result.key, is(genericKey(OLD_KEY + "-foo", null)));
assertThat(result.value, is(nullValue()));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByKeyExpression.
@Test
public void shouldPropagateNullValueWhenPartitioningByKeyExpression() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")))).getMapper();
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, null);
// Then:
assertThat(result.key, is(genericKey((OLD_KEY + "-foo"))));
assertThat(result.value, is(nullValue()));
}
Aggregations