Search in sources :

Example 1 with FlinkContextImpl

use of org.apache.flink.table.planner.calcite.FlinkContextImpl in project flink by apache.

the class RexWindowBoundSerdeTest method testSerde.

@Test
public void testSerde() throws IOException {
    SerdeContext serdeCtx = new SerdeContext(null, new FlinkContextImpl(false, TableConfig.getDefault(), new ModuleManager(), null, CatalogManagerMocks.createEmptyCatalogManager(), null), Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
    ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
    ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
    assertEquals(RexWindowBounds.CURRENT_ROW, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.CURRENT_ROW), RexWindowBound.class));
    assertEquals(RexWindowBounds.UNBOUNDED_FOLLOWING, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.UNBOUNDED_FOLLOWING), RexWindowBound.class));
    assertEquals(RexWindowBounds.UNBOUNDED_PRECEDING, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.UNBOUNDED_PRECEDING), RexWindowBound.class));
    RexBuilder builder = new RexBuilder(FlinkTypeFactory.INSTANCE());
    RexWindowBound windowBound = RexWindowBounds.following(builder.makeLiteral("test"));
    assertEquals(windowBound, objectReader.readValue(objectWriter.writeValueAsString(windowBound), RexWindowBound.class));
    windowBound = RexWindowBounds.preceding(builder.makeLiteral("test"));
    assertEquals(windowBound, objectReader.readValue(objectWriter.writeValueAsString(windowBound), RexWindowBound.class));
}
Also used : FlinkContextImpl(org.apache.flink.table.planner.calcite.FlinkContextImpl) RexWindowBound(org.apache.calcite.rex.RexWindowBound) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) RexBuilder(org.apache.calcite.rex.RexBuilder) ObjectReader(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader) ModuleManager(org.apache.flink.table.module.ModuleManager) Test(org.junit.Test)

Example 2 with FlinkContextImpl

use of org.apache.flink.table.planner.calcite.FlinkContextImpl 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);
    }
}
Also used : FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) BigIntType(org.apache.flink.table.types.logical.BigIntType) ModuleManager(org.apache.flink.table.module.ModuleManager) FlinkContext(org.apache.flink.table.planner.calcite.FlinkContext) CatalogManager(org.apache.flink.table.catalog.CatalogManager) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) LookupJoinUtil(org.apache.flink.table.planner.plan.utils.LookupJoinUtil) FlinkContextImpl(org.apache.flink.table.planner.calcite.FlinkContextImpl) TableConfig(org.apache.flink.table.api.TableConfig) RexBuilder(org.apache.calcite.rex.RexBuilder) ObjectReader(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Example 3 with FlinkContextImpl

use of org.apache.flink.table.planner.calcite.FlinkContextImpl in project flink by apache.

the class LogicalWindowSerdeTest method testLogicalWindowSerde.

@Test
public void testLogicalWindowSerde() throws IOException {
    SerdeContext serdeCtx = new SerdeContext(null, new FlinkContextImpl(false, TableConfig.getDefault(), new ModuleManager(), null, CatalogManagerMocks.createEmptyCatalogManager(), null), Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
    ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
    ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
    assertEquals(objectReader.readValue(objectWriter.writeValueAsString(window), LogicalWindow.class), window);
}
Also used : LogicalWindow(org.apache.flink.table.planner.plan.logical.LogicalWindow) FlinkContextImpl(org.apache.flink.table.planner.calcite.FlinkContextImpl) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader) ModuleManager(org.apache.flink.table.module.ModuleManager) Test(org.junit.Test)

Aggregations

ObjectReader (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader)3 ObjectWriter (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter)3 ModuleManager (org.apache.flink.table.module.ModuleManager)3 FlinkContextImpl (org.apache.flink.table.planner.calcite.FlinkContextImpl)3 Test (org.junit.Test)3 RexBuilder (org.apache.calcite.rex.RexBuilder)2 RexWindowBound (org.apache.calcite.rex.RexWindowBound)1 TableConfig (org.apache.flink.table.api.TableConfig)1 CatalogManager (org.apache.flink.table.catalog.CatalogManager)1 FunctionCatalog (org.apache.flink.table.catalog.FunctionCatalog)1 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)1 FlinkContext (org.apache.flink.table.planner.calcite.FlinkContext)1 LogicalWindow (org.apache.flink.table.planner.plan.logical.LogicalWindow)1 LookupJoinUtil (org.apache.flink.table.planner.plan.utils.LookupJoinUtil)1 BigIntType (org.apache.flink.table.types.logical.BigIntType)1