use of org.apache.flink.table.catalog.CatalogManager in project flink by apache.
the class LookupKeySerdeTest method testLookupKey.
@Test
public void testLookupKey() throws IOException {
TableConfig tableConfig = TableConfig.getDefault();
ModuleManager moduleManager = new ModuleManager();
CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(Thread.currentThread().getContextClassLoader()).config(tableConfig.getConfiguration()).defaultCatalog("default_catalog", new GenericInMemoryCatalog("default_db")).build();
FlinkContext flinkContext = new FlinkContextImpl(false, tableConfig, moduleManager, new FunctionCatalog(tableConfig, catalogManager, moduleManager), catalogManager, null);
SerdeContext serdeCtx = new SerdeContext(null, flinkContext, Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
LookupJoinUtil.LookupKey[] lookupKeys = new LookupJoinUtil.LookupKey[] { new LookupJoinUtil.ConstantLookupKey(new BigIntType(), new RexBuilder(FlinkTypeFactory.INSTANCE()).makeLiteral("a")), new LookupJoinUtil.FieldRefLookupKey(3) };
for (LookupJoinUtil.LookupKey lookupKey : lookupKeys) {
LookupJoinUtil.LookupKey result = objectReader.readValue(objectWriter.writeValueAsString(lookupKey), LookupJoinUtil.LookupKey.class);
assertEquals(lookupKey, result);
}
}
use of org.apache.flink.table.catalog.CatalogManager 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.catalog.CatalogManager 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(",");
}
use of org.apache.flink.table.catalog.CatalogManager in project flink by apache.
the class TemporalTableSourceSpecSerdeTest method testTemporalTableSourceSpecSerde.
@ParameterizedTest
@MethodSource("testTemporalTableSourceSpecSerde")
public void testTemporalTableSourceSpecSerde(TemporalTableSourceSpec spec) throws IOException {
CatalogManager catalogManager = CatalogManagerMocks.createEmptyCatalogManager();
catalogManager.createTemporaryTable(spec.getTableSourceSpec().getContextResolvedTable().getResolvedTable(), spec.getTableSourceSpec().getContextResolvedTable().getIdentifier(), false);
SerdeContext serdeCtx = JsonSerdeTestUtil.configuredSerdeContext(catalogManager, new TableConfig());
String json = JsonSerdeTestUtil.toJson(serdeCtx, spec);
TemporalTableSourceSpec actual = JsonSerdeTestUtil.toObject(serdeCtx, json, TemporalTableSourceSpec.class);
assertThat(actual.getTableSourceSpec().getContextResolvedTable()).isEqualTo(spec.getTableSourceSpec().getContextResolvedTable());
assertThat(actual.getTableSourceSpec().getSourceAbilities()).isEqualTo(spec.getTableSourceSpec().getSourceAbilities());
assertThat(actual.getOutputType()).isEqualTo(spec.getOutputType());
}
use of org.apache.flink.table.catalog.CatalogManager in project flink by apache.
the class DatabaseCalciteSchemaTest method testPermanentTableWithPrimaryKey.
@Test
public void testPermanentTableWithPrimaryKey() {
final CatalogManager catalogManager = CatalogManagerMocks.createEmptyCatalogManager();
final DatabaseCalciteSchema calciteSchema = new DatabaseCalciteSchema(DEFAULT_CATALOG, DEFAULT_DATABASE, catalogManager, true);
catalogManager.createTable(createTable(), ObjectIdentifier.of(DEFAULT_CATALOG, DEFAULT_DATABASE, TABLE_NAME), false);
final Table table = calciteSchema.getTable(TABLE_NAME);
assertThat(table, instanceOf(CatalogSchemaTable.class));
assertThat(((CatalogSchemaTable) table).getStatistic().getUniqueKeys().iterator().next(), containsInAnyOrder("a", "b"));
}
Aggregations