use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldBuildWithRowtime.
@Test
public void shouldBuildWithRowtime() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
final List<ColumnName> names = ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, COL0);
final Expression exp = new StringLiteral("a");
// When:
final KsqlGenericRecord record = recordFactory.build(names, ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM);
// Then:
assertThat(record, is(KsqlGenericRecord.of(GenericKey.genericKey("a"), GenericRow.genericRow("a"), 1)));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnInsertRowpartition.
@Test
public void shouldThrowOnInsertRowpartition() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
final Expression exp = new StringLiteral("a");
when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, SystemColumns.ROWPARTITION_NAME), ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Inserting into column `ROWPARTITION` is not allowed."));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class SchemaKTableTest method shouldRewriteTimeComparisonInFilter.
@Test
public void shouldRewriteTimeComparisonInFilter() {
// Given:
final String selectQuery = "SELECT col0, col2, col3 FROM test2 " + "WHERE ROWTIME = '1984-01-01T00:00:00+00:00' EMIT CHANGES;";
final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
final FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
// When:
final SchemaKTable<?> filteredSchemaKTable = initialSchemaKTable.filter(filterNode.getPredicate(), childContextStacker);
// Then:
final TableFilter<?> step = (TableFilter) filteredSchemaKTable.getSourceTableStep();
assertThat(step.getFilterExpression(), Matchers.equalTo(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("ROWTIME")), new LongLiteral(441763200000L))));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldHandleNegativeValueExpression.
@Test
public void shouldHandleNegativeValueExpression() {
// Given:
givenSourceStreamWithSchema(SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(COL0, COL1), ImmutableList.of(new StringLiteral("str"), ArithmeticUnaryExpression.negative(Optional.empty(), new LongLiteral(1))));
// When:
executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
// Then:
verify(keySerializer).serialize(TOPIC_NAME, genericKey((String) null));
verify(valueSerializer).serialize(TOPIC_NAME, genericRow("str", -1L));
verify(producer).send(new ProducerRecord<>(TOPIC_NAME, null, 1L, KEY, VALUE));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowWhenNotAuthorizedToWriteValSchemaToSR.
@Test
public void shouldThrowWhenNotAuthorizedToWriteValSchemaToSR() throws Exception {
// Given:
when(srClient.getLatestSchemaMetadata(Mockito.any())).thenReturn(new SchemaMetadata(1, 1, "\"string\""));
givenDataSourceWithSchema(TOPIC_NAME, SCHEMA, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of(), FormatInfo.of(FormatFactory.AVRO.name()), FormatInfo.of(FormatFactory.AVRO.name()), false, false);
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allColumnNames(SCHEMA), ImmutableList.of(new StringLiteral("key"), new StringLiteral("str"), new LongLiteral(2L)));
when(valueSerializer.serialize(any(), any())).thenThrow(new RuntimeException(new RestClientException("foo", 401, 1)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("Authorization denied to Write on Schema Registry subject: [" + KsqlConstants.getSRSubject(TOPIC_NAME, false)));
}
Aggregations