-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: serialize/deserialize plans from qtt #4080
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,17 @@ | |
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableList; | ||
import io.confluent.kafka.schemaregistry.client.SchemaMetadata; | ||
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient; | ||
import io.confluent.ksql.KsqlExecutionContext; | ||
import io.confluent.ksql.KsqlExecutionContext.ExecuteResult; | ||
import io.confluent.ksql.engine.KsqlEngine; | ||
import io.confluent.ksql.engine.KsqlPlan; | ||
import io.confluent.ksql.engine.SqlFormatInjector; | ||
import io.confluent.ksql.engine.StubInsertValuesExecutor; | ||
import io.confluent.ksql.execution.json.PlanJsonMapper; | ||
import io.confluent.ksql.metastore.MetaStore; | ||
import io.confluent.ksql.metastore.model.DataSource; | ||
import io.confluent.ksql.name.SourceName; | ||
|
@@ -41,12 +44,14 @@ | |
import io.confluent.ksql.parser.tree.Query; | ||
import io.confluent.ksql.parser.tree.Relation; | ||
import io.confluent.ksql.parser.tree.Table; | ||
import io.confluent.ksql.planner.plan.ConfiguredKsqlPlan; | ||
import io.confluent.ksql.schema.ksql.inference.DefaultSchemaInjector; | ||
import io.confluent.ksql.schema.ksql.inference.SchemaRegistryTopicSchemaSupplier; | ||
import io.confluent.ksql.serde.Format; | ||
import io.confluent.ksql.services.KafkaTopicClient; | ||
import io.confluent.ksql.services.ServiceContext; | ||
import io.confluent.ksql.statement.ConfiguredStatement; | ||
import io.confluent.ksql.test.TestFrameworkException; | ||
import io.confluent.ksql.test.serde.SerdeSupplier; | ||
import io.confluent.ksql.test.tools.stubs.StubKafkaService; | ||
import io.confluent.ksql.test.utils.SerdeUtil; | ||
|
@@ -55,6 +60,7 @@ | |
import io.confluent.ksql.util.KsqlException; | ||
import io.confluent.ksql.util.KsqlStatementException; | ||
import io.confluent.ksql.util.PersistentQueryMetadata; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -71,6 +77,8 @@ | |
public final class TestExecutorUtil { | ||
// CHECKSTYLE_RULES.ON: ClassDataAbstractionCoupling | ||
|
||
private static final ObjectMapper PLAN_MAPPER = PlanJsonMapper.create(); | ||
|
||
private TestExecutorUtil() { | ||
} | ||
|
||
|
@@ -275,7 +283,6 @@ private static List<PersistentQueryAndSortedSources> execute( | |
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
private static ExecuteResultAndSortedSources execute( | ||
final KsqlExecutionContext executionContext, | ||
|
@@ -308,7 +315,7 @@ private static ExecuteResultAndSortedSources execute( | |
|
||
final ExecuteResult executeResult; | ||
try { | ||
executeResult = executionContext.execute(executionContext.getServiceContext(), reformatted); | ||
executeResult = executeConfiguredStatement(executionContext, reformatted); | ||
} catch (final KsqlStatementException statementException) { | ||
// use the original statement text in the exception so that tests | ||
// can easily check that the failed statement is the input statement | ||
|
@@ -339,6 +346,31 @@ private static ExecuteResultAndSortedSources execute( | |
Optional.empty()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't think this suppression is needed |
||
private static ExecuteResult executeConfiguredStatement( | ||
final KsqlExecutionContext executionContext, | ||
final ConfiguredStatement<?> stmt) { | ||
final ConfiguredKsqlPlan configuredPlan; | ||
try { | ||
configuredPlan = buildConfiguredPlan(executionContext, stmt); | ||
} catch (final IOException e) { | ||
throw new TestFrameworkException("Error (de)serializing plan: " + e.getMessage(), e); | ||
} | ||
return executionContext.execute(executionContext.getServiceContext(), configuredPlan); | ||
} | ||
|
||
private static ConfiguredKsqlPlan buildConfiguredPlan( | ||
final KsqlExecutionContext executionContext, | ||
final ConfiguredStatement<?> stmt | ||
) throws IOException { | ||
final KsqlPlan plan = executionContext.plan(executionContext.getServiceContext(), stmt); | ||
final String serialized = PLAN_MAPPER.writeValueAsString(plan); | ||
return ConfiguredKsqlPlan.of( | ||
PLAN_MAPPER.readValue(serialized, KsqlPlan.class), | ||
stmt.getOverrides(), | ||
stmt.getConfig()); | ||
} | ||
|
||
private static Optional<Long> getWindowSize(final Query query) { | ||
return query.getWindow().flatMap(window -> window | ||
.getKsqlWindowExpression() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.client.json; | ||
package io.confluent.ksql.parser.json; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
@@ -25,6 +25,11 @@ | |
import java.io.IOException; | ||
|
||
final class LogicalSchemaDeserializer extends JsonDeserializer<LogicalSchema> { | ||
final boolean withImplicitColumns; | ||
|
||
LogicalSchemaDeserializer(final boolean withImplicitColumns) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this because when deserializing ddl schemas we do want the implicit columns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of interest, is it just ROWTIME you need? I'm hoping to completely remove the concept of 'implicit' column soon by:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
you mean ROWKEY? |
||
this.withImplicitColumns = withImplicitColumns; | ||
} | ||
|
||
@Override | ||
public LogicalSchema deserialize( | ||
|
@@ -36,6 +41,6 @@ public LogicalSchema deserialize( | |
|
||
final TableElements tableElements = SchemaParser.parse(text, TypeRegistry.EMPTY); | ||
|
||
return tableElements.toLogicalSchema(false); | ||
return tableElements.toLogicalSchema(withImplicitColumns); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason Jackson complains it can't deserialize into ImmutableList when using the JsonCreator (even though it ultimately just calls this constructor). So I switched this class to use a custom deserializer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because there is a getter called
getContext
, so its checking out theprivate final ImmutableList<String> context;
field. MarkgetContext
as@JsonIgnore
and you'll be golden.