use of org.apache.flink.table.module.ModuleManager 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));
}
use of org.apache.flink.table.module.ModuleManager in project flink by apache.
the class JsonSerdeTestUtil method configuredSerdeContext.
static SerdeContext configuredSerdeContext(CatalogManager catalogManager, TableConfig tableConfig) {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ModuleManager moduleManager = new ModuleManager();
final FunctionCatalog functionCatalog = new FunctionCatalog(tableConfig, catalogManager, moduleManager);
final PlannerContext plannerContext = new PlannerContext(false, tableConfig, moduleManager, functionCatalog, catalogManager, asRootSchema(new CatalogManagerCalciteSchema(catalogManager, true)), Collections.emptyList());
return new SerdeContext(new ParserImpl(null, null, plannerContext::createCalciteParser, null), plannerContext.getFlinkContext(), classLoader, FlinkTypeFactory.INSTANCE(), plannerContext.createFrameworkConfig().getOperatorTable());
}
use of org.apache.flink.table.module.ModuleManager in project flink by apache.
the class SessionContext method create.
// --------------------------------------------------------------------------------------------
// Helper method to create
// --------------------------------------------------------------------------------------------
public static SessionContext create(DefaultContext defaultContext, String sessionId) {
// --------------------------------------------------------------------------------------------------------------
// Init config
// --------------------------------------------------------------------------------------------------------------
Configuration configuration = defaultContext.getFlinkConfig().clone();
// --------------------------------------------------------------------------------------------------------------
// Init classloader
// --------------------------------------------------------------------------------------------------------------
URLClassLoader classLoader = ClientUtils.buildUserCodeClassLoader(defaultContext.getDependencies(), Collections.emptyList(), SessionContext.class.getClassLoader(), configuration);
// --------------------------------------------------------------------------------------------------------------
// Init session state
// --------------------------------------------------------------------------------------------------------------
ModuleManager moduleManager = new ModuleManager();
final EnvironmentSettings settings = EnvironmentSettings.fromConfiguration(configuration);
CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(classLoader).config(configuration).defaultCatalog(settings.getBuiltInCatalogName(), new GenericInMemoryCatalog(settings.getBuiltInCatalogName(), settings.getBuiltInDatabaseName())).build();
FunctionCatalog functionCatalog = new FunctionCatalog(configuration, catalogManager, moduleManager);
SessionState sessionState = new SessionState(catalogManager, moduleManager, functionCatalog);
// --------------------------------------------------------------------------------------------------------------
// Init ExecutionContext
// --------------------------------------------------------------------------------------------------------------
ExecutionContext executionContext = new ExecutionContext(configuration, classLoader, sessionState);
return new SessionContext(defaultContext, sessionId, configuration, classLoader, sessionState, executionContext);
}
use of org.apache.flink.table.module.ModuleManager in project flink by apache.
the class StreamTableEnvironmentImplTest method getStreamTableEnvironment.
private StreamTableEnvironmentImpl getStreamTableEnvironment(StreamExecutionEnvironment env, DataStreamSource<Integer> elements) {
TableConfig tableConfig = new TableConfig();
CatalogManager catalogManager = CatalogManagerMocks.createEmptyCatalogManager();
ModuleManager moduleManager = new ModuleManager();
return new StreamTableEnvironmentImpl(catalogManager, moduleManager, new FunctionCatalog(tableConfig, catalogManager, moduleManager), tableConfig, env, new TestPlanner(elements.getTransformation()), new ExecutorMock(), true, this.getClass().getClassLoader());
}
use of org.apache.flink.table.module.ModuleManager in project zeppelin by apache.
the class TableEnvFactory method createJavaFlinkStreamTableEnvironment.
public TableEnvironment createJavaFlinkStreamTableEnvironment(EnvironmentSettings settings, ClassLoader classLoader) {
try {
ImmutablePair<Object, Object> pair = flinkShims.createPlannerAndExecutor(classLoader, settings, senv.getJavaEnv(), oldPlannerBatchTableConfig, functionCatalog, catalogManager);
Planner planner = (Planner) pair.left;
Executor executor = (Executor) pair.right;
Class clazz = Class.forName("org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl");
try {
Constructor constructor = clazz.getConstructor(CatalogManager.class, ModuleManager.class, FunctionCatalog.class, TableConfig.class, org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.class, Planner.class, Executor.class, boolean.class);
return (TableEnvironment) constructor.newInstance(oldPlannerCatalogManager, moduleManager, oldPlannerFunctionCatalog, oldPlannerStreamTableConfig, senv.getJavaEnv(), planner, executor, settings.isStreamingMode());
} catch (NoSuchMethodException e) {
// Flink 1.11.1 change the constructor signature, FLINK-18419
Constructor constructor = clazz.getConstructor(CatalogManager.class, ModuleManager.class, FunctionCatalog.class, TableConfig.class, org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.class, Planner.class, Executor.class, boolean.class, ClassLoader.class);
return (TableEnvironment) constructor.newInstance(oldPlannerCatalogManager, moduleManager, oldPlannerFunctionCatalog, oldPlannerStreamTableConfig, senv.getJavaEnv(), planner, executor, settings.isStreamingMode(), classLoader);
}
} catch (Exception e) {
throw new TableException("Fail to createJavaFlinkStreamTableEnvironment", e);
}
}
Aggregations