Search in sources :

Example 31 with TableConfig

use of org.apache.flink.table.api.TableConfig in project flink by apache.

the class StreamTableEnvironment method create.

/**
 * Creates a table environment that is the entry point and central context for creating Table
 * and SQL API programs that integrate with the Java-specific {@link DataStream} API.
 *
 * <p>It is unified for bounded and unbounded data processing.
 *
 * <p>A stream table environment is responsible for:
 *
 * <ul>
 *   <li>Convert a {@link DataStream} into {@link Table} and vice-versa.
 *   <li>Connecting to external systems.
 *   <li>Registering and retrieving {@link Table}s and other meta objects from a catalog.
 *   <li>Executing SQL statements.
 *   <li>Offering further configuration options.
 * </ul>
 *
 * <p>Note: If you don't intend to use the {@link DataStream} API, {@link TableEnvironment} is
 * meant for pure table programs.
 *
 * @param executionEnvironment The Java {@link StreamExecutionEnvironment} of the {@link
 *     TableEnvironment}.
 * @param settings The environment settings used to instantiate the {@link TableEnvironment}.
 */
static StreamTableEnvironment create(StreamExecutionEnvironment executionEnvironment, EnvironmentSettings settings) {
    TableConfig tableConfig = new TableConfig();
    tableConfig.addConfiguration(settings.toConfiguration());
    return StreamTableEnvironmentImpl.create(executionEnvironment, settings, tableConfig);
}
Also used : TableConfig(org.apache.flink.table.api.TableConfig)

Example 32 with TableConfig

use of org.apache.flink.table.api.TableConfig 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 33 with TableConfig

use of org.apache.flink.table.api.TableConfig 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());
}
Also used : TemporalTableSourceSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.TemporalTableSourceSpec) TableConfig(org.apache.flink.table.api.TableConfig) CatalogManager(org.apache.flink.table.catalog.CatalogManager) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 34 with TableConfig

use of org.apache.flink.table.api.TableConfig in project flink by apache.

the class PushLocalAggIntoScanRuleBase method canPushDown.

protected boolean canPushDown(RelOptRuleCall call, BatchPhysicalGroupAggregateBase aggregate, BatchPhysicalTableSourceScan tableSourceScan) {
    TableConfig tableConfig = ShortcutUtils.unwrapContext(call.getPlanner()).getTableConfig();
    if (!tableConfig.getConfiguration().getBoolean(OptimizerConfigOptions.TABLE_OPTIMIZER_SOURCE_AGGREGATE_PUSHDOWN_ENABLED)) {
        return false;
    }
    if (aggregate.isFinal() || aggregate.getAggCallList().isEmpty()) {
        return false;
    }
    List<AggregateCall> aggCallList = JavaScalaConversionUtil.toJava(aggregate.getAggCallList());
    for (AggregateCall aggCall : aggCallList) {
        if (aggCall.isDistinct() || aggCall.isApproximate() || aggCall.getArgList().size() > 1 || aggCall.hasFilter() || !aggCall.getCollation().getFieldCollations().isEmpty()) {
            return false;
        }
    }
    TableSourceTable tableSourceTable = tableSourceScan.tableSourceTable();
    // we can not push aggregates twice
    return tableSourceTable != null && tableSourceTable.tableSource() instanceof SupportsAggregatePushDown && Arrays.stream(tableSourceTable.abilitySpecs()).noneMatch(spec -> spec instanceof AggregatePushDownSpec);
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) SupportsAggregatePushDown(org.apache.flink.table.connector.source.abilities.SupportsAggregatePushDown) Arrays(java.util.Arrays) RexProgram(org.apache.calcite.rex.RexProgram) AggregatePushDownSpec(org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec) SourceAbilityContext(org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext) RexNodeExtractor(org.apache.flink.table.planner.plan.utils.RexNodeExtractor) ShortcutUtils(org.apache.flink.table.planner.utils.ShortcutUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ArrayList(java.util.ArrayList) OptimizerConfigOptions(org.apache.flink.table.api.config.OptimizerConfigOptions) BatchPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc) RelOptRuleOperand(org.apache.calcite.plan.RelOptRuleOperand) RexNode(org.apache.calcite.rex.RexNode) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) TableConfig(org.apache.flink.table.api.TableConfig) ProjectPushDownSpec(org.apache.flink.table.planner.plan.abilities.source.ProjectPushDownSpec) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan) BatchPhysicalGroupAggregateBase(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase) Collectors(java.util.stream.Collectors) SourceAbilitySpec(org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) RexInputRef(org.apache.calcite.rex.RexInputRef) RelOptRule(org.apache.calcite.plan.RelOptRule) List(java.util.List) BatchPhysicalExchange(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalExchange) FlinkStatistic(org.apache.flink.table.planner.plan.stats.FlinkStatistic) JavaScalaConversionUtil(org.apache.flink.table.planner.utils.JavaScalaConversionUtil) AggregateCall(org.apache.calcite.rel.core.AggregateCall) Collections(java.util.Collections) AggregatePushDownSpec(org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec) TableConfig(org.apache.flink.table.api.TableConfig) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) SupportsAggregatePushDown(org.apache.flink.table.connector.source.abilities.SupportsAggregatePushDown)

Example 35 with TableConfig

use of org.apache.flink.table.api.TableConfig in project flink by apache.

the class TwoStageOptimizedWindowAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    final StreamPhysicalWindowAggregate windowAgg = call.rel(0);
    final RelNode realInput = call.rel(2);
    final TableConfig tableConfig = unwrapContext(call.getPlanner()).getTableConfig();
    final WindowingStrategy windowing = windowAgg.windowing();
    // the two-phase optimization must be enabled
    if (getAggPhaseStrategy(tableConfig) == AggregatePhaseStrategy.ONE_PHASE) {
        return false;
    }
    // otherwise the processing-time can't be materialized in a single node
    if (!windowing.isRowtime()) {
        return false;
    }
    // all aggregate function should support merge() method
    if (!AggregateUtil.doAllSupportPartialMerge(windowAgg.aggInfoList().aggInfos())) {
        return false;
    }
    return !isInputSatisfyRequiredDistribution(realInput, windowAgg.grouping());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) StreamPhysicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalWindowAggregate) TableConfig(org.apache.flink.table.api.TableConfig) WindowAttachedWindowingStrategy(org.apache.flink.table.planner.plan.logical.WindowAttachedWindowingStrategy) TimeAttributeWindowingStrategy(org.apache.flink.table.planner.plan.logical.TimeAttributeWindowingStrategy) WindowingStrategy(org.apache.flink.table.planner.plan.logical.WindowingStrategy) SliceAttachedWindowingStrategy(org.apache.flink.table.planner.plan.logical.SliceAttachedWindowingStrategy)

Aggregations

TableConfig (org.apache.flink.table.api.TableConfig)41 RowType (org.apache.flink.table.types.logical.RowType)19 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)6 RexNode (org.apache.calcite.rex.RexNode)6 CatalogManager (org.apache.flink.table.catalog.CatalogManager)6 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 PrintStream (java.io.PrintStream)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 List (java.util.List)5 RexBuilder (org.apache.calcite.rex.RexBuilder)5 RexInputRef (org.apache.calcite.rex.RexInputRef)5 Table (org.apache.flink.table.api.Table)5 FlinkTypeFactory (org.apache.flink.table.planner.calcite.FlinkTypeFactory)5 IntType (org.apache.flink.table.types.logical.IntType)5 Row (org.apache.flink.types.Row)5 Random (java.util.Random)4 Consumer (java.util.function.Consumer)4