use of org.apache.flink.table.planner.utils.PlannerMocks in project flink by apache.
the class DynamicTableSourceSpecSerdeTest method testDynamicTableSourceSpecSerde.
@ParameterizedTest
@MethodSource("testDynamicTableSinkSpecSerde")
void testDynamicTableSourceSpecSerde(DynamicTableSourceSpec spec) throws IOException {
PlannerMocks plannerMocks = PlannerMocks.create();
CatalogManager catalogManager = plannerMocks.getCatalogManager();
catalogManager.createTable(spec.getContextResolvedTable().getResolvedTable(), spec.getContextResolvedTable().getIdentifier(), false);
SerdeContext serdeCtx = configuredSerdeContext(catalogManager, plannerMocks.getTableConfig());
// Re-init the spec to be permanent with correct catalog
spec = new DynamicTableSourceSpec(ContextResolvedTable.permanent(spec.getContextResolvedTable().getIdentifier(), catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get(), spec.getContextResolvedTable().getResolvedTable()), spec.getSourceAbilities());
String actualJson = toJson(serdeCtx, spec);
DynamicTableSourceSpec actual = toObject(serdeCtx, actualJson, DynamicTableSourceSpec.class);
assertThat(actual.getContextResolvedTable()).isEqualTo(spec.getContextResolvedTable());
assertThat(actual.getSourceAbilities()).isEqualTo(spec.getSourceAbilities());
assertThat(actual.getScanTableSource(plannerMocks.getPlannerContext().getFlinkContext())).isNotNull();
}
use of org.apache.flink.table.planner.utils.PlannerMocks in project flink by apache.
the class DynamicTableSourceSpecSerdeTest method testDynamicTableSourceSpecSerdeWithEnrichmentOptions.
@Test
void testDynamicTableSourceSpecSerdeWithEnrichmentOptions() throws Exception {
// Test model
ObjectIdentifier identifier = ObjectIdentifier.of(DEFAULT_BUILTIN_CATALOG, DEFAULT_BUILTIN_DATABASE, "my_table");
String formatPrefix = FactoryUtil.getFormatPrefix(FORMAT, TestFormatFactory.IDENTIFIER);
Map<String, String> planOptions = new HashMap<>();
planOptions.put(CONNECTOR.key(), TestDynamicTableFactory.IDENTIFIER);
planOptions.put(TARGET.key(), "abc");
planOptions.put(PASSWORD.key(), "abc");
planOptions.put(FORMAT.key(), TestFormatFactory.IDENTIFIER);
planOptions.put(formatPrefix + DELIMITER.key(), "|");
Map<String, String> catalogOptions = new HashMap<>();
catalogOptions.put(CONNECTOR.key(), TestDynamicTableFactory.IDENTIFIER);
catalogOptions.put(TARGET.key(), "abc");
catalogOptions.put(PASSWORD.key(), "xyz");
catalogOptions.put(FORMAT.key(), TestFormatFactory.IDENTIFIER);
catalogOptions.put(formatPrefix + DELIMITER.key(), ",");
ResolvedCatalogTable planResolvedCatalogTable = tableWithOnlyPhysicalColumns(planOptions);
ResolvedCatalogTable catalogResolvedCatalogTable = tableWithOnlyPhysicalColumns(catalogOptions);
// Create planner mocks
PlannerMocks plannerMocks = PlannerMocks.create(new Configuration().set(PLAN_RESTORE_CATALOG_OBJECTS, CatalogPlanRestore.ALL).set(PLAN_COMPILE_CATALOG_OBJECTS, CatalogPlanCompilation.ALL));
CatalogManager catalogManager = plannerMocks.getCatalogManager();
catalogManager.createTable(catalogResolvedCatalogTable, identifier, false);
// Mock the context
SerdeContext serdeCtx = configuredSerdeContext(catalogManager, plannerMocks.getTableConfig());
DynamicTableSourceSpec planSpec = new DynamicTableSourceSpec(ContextResolvedTable.permanent(identifier, catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get(), planResolvedCatalogTable), Collections.emptyList());
String actualJson = toJson(serdeCtx, planSpec);
DynamicTableSourceSpec actual = toObject(serdeCtx, actualJson, DynamicTableSourceSpec.class);
assertThat(actual.getContextResolvedTable()).isEqualTo(planSpec.getContextResolvedTable());
assertThat(actual.getSourceAbilities()).isNull();
TestDynamicTableFactory.DynamicTableSourceMock dynamicTableSource = (TestDynamicTableFactory.DynamicTableSourceMock) actual.getScanTableSource(plannerMocks.getPlannerContext().getFlinkContext());
assertThat(dynamicTableSource.password).isEqualTo("xyz");
assertThat(((TestFormatFactory.DecodingFormatMock) dynamicTableSource.valueFormat).delimiter).isEqualTo(",");
}
use of org.apache.flink.table.planner.utils.PlannerMocks in project flink by apache.
the class DynamicTableSinkSpecSerdeTest method testDynamicTableSinkSpecSerde.
@ParameterizedTest
@MethodSource("testDynamicTableSinkSpecSerde")
void testDynamicTableSinkSpecSerde(DynamicTableSinkSpec spec) throws IOException {
PlannerMocks plannerMocks = PlannerMocks.create();
CatalogManager catalogManager = plannerMocks.getCatalogManager();
catalogManager.createTable(spec.getContextResolvedTable().getResolvedTable(), spec.getContextResolvedTable().getIdentifier(), false);
SerdeContext serdeCtx = configuredSerdeContext(catalogManager, plannerMocks.getTableConfig());
// Re-init the spec to be permanent with correct catalog
spec = new DynamicTableSinkSpec(ContextResolvedTable.permanent(spec.getContextResolvedTable().getIdentifier(), catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get(), spec.getContextResolvedTable().getResolvedTable()), spec.getSinkAbilities());
String actualJson = toJson(serdeCtx, spec);
DynamicTableSinkSpec actual = toObject(serdeCtx, actualJson, DynamicTableSinkSpec.class);
assertThat(actual.getContextResolvedTable()).isEqualTo(spec.getContextResolvedTable());
assertThat(actual.getSinkAbilities()).isEqualTo(spec.getSinkAbilities());
assertThat(actual.getTableSink(plannerMocks.getPlannerContext().getFlinkContext())).isNotNull();
}
use of org.apache.flink.table.planner.utils.PlannerMocks in project flink by apache.
the class DynamicTableSinkSpecSerdeTest method testDynamicTableSinkSpecSerdeWithEnrichmentOptions.
@Test
void testDynamicTableSinkSpecSerdeWithEnrichmentOptions() throws Exception {
// Test model
ObjectIdentifier identifier = ObjectIdentifier.of(DEFAULT_BUILTIN_CATALOG, DEFAULT_BUILTIN_DATABASE, "my_table");
String formatPrefix = FactoryUtil.getFormatPrefix(FORMAT, TestFormatFactory.IDENTIFIER);
Map<String, String> planOptions = new HashMap<>();
planOptions.put(CONNECTOR.key(), TestDynamicTableFactory.IDENTIFIER);
planOptions.put(TARGET.key(), "abc");
planOptions.put(BUFFER_SIZE.key(), "1000");
planOptions.put(FORMAT.key(), TestFormatFactory.IDENTIFIER);
planOptions.put(formatPrefix + DELIMITER.key(), "|");
Map<String, String> catalogOptions = new HashMap<>();
catalogOptions.put(CONNECTOR.key(), TestDynamicTableFactory.IDENTIFIER);
catalogOptions.put(TARGET.key(), "xyz");
catalogOptions.put(BUFFER_SIZE.key(), "2000");
catalogOptions.put(FORMAT.key(), TestFormatFactory.IDENTIFIER);
catalogOptions.put(formatPrefix + DELIMITER.key(), ",");
ResolvedCatalogTable planResolvedCatalogTable = tableWithOnlyPhysicalColumns(planOptions);
ResolvedCatalogTable catalogResolvedCatalogTable = tableWithOnlyPhysicalColumns(catalogOptions);
// Create planner mocks
PlannerMocks plannerMocks = PlannerMocks.create(new Configuration().set(PLAN_RESTORE_CATALOG_OBJECTS, CatalogPlanRestore.ALL).set(PLAN_COMPILE_CATALOG_OBJECTS, CatalogPlanCompilation.ALL));
CatalogManager catalogManager = plannerMocks.getCatalogManager();
catalogManager.createTable(catalogResolvedCatalogTable, identifier, false);
// Mock the context
SerdeContext serdeCtx = configuredSerdeContext(catalogManager, plannerMocks.getTableConfig());
DynamicTableSinkSpec planSpec = new DynamicTableSinkSpec(ContextResolvedTable.permanent(identifier, catalogManager.getCatalog(catalogManager.getCurrentCatalog()).get(), planResolvedCatalogTable), Collections.emptyList());
String actualJson = toJson(serdeCtx, planSpec);
DynamicTableSinkSpec actual = toObject(serdeCtx, actualJson, DynamicTableSinkSpec.class);
assertThat(actual.getContextResolvedTable()).isEqualTo(planSpec.getContextResolvedTable());
assertThat(actual.getSinkAbilities()).isNull();
TestDynamicTableFactory.DynamicTableSinkMock dynamicTableSink = (TestDynamicTableFactory.DynamicTableSinkMock) actual.getTableSink(plannerMocks.getPlannerContext().getFlinkContext());
assertThat(dynamicTableSink.target).isEqualTo("abc");
assertThat(dynamicTableSink.bufferSize).isEqualTo(2000);
assertThat(((TestFormatFactory.EncodingFormatMock) dynamicTableSink.valueFormat).delimiter).isEqualTo(",");
}
Aggregations