Search in sources :

Example 36 with TableConfig

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

the class PlannerMocks method create.

public static PlannerMocks create(Configuration configuration) {
    TableConfig tableConfig = new TableConfig();
    tableConfig.addConfiguration(configuration);
    return new PlannerMocks(tableConfig);
}
Also used : TableConfig(org.apache.flink.table.api.TableConfig)

Example 37 with TableConfig

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

the class PushProjectIntoTableSourceScanRule method getProjections.

private List<RexNode> getProjections(LogicalProject project, LogicalTableScan scan) {
    final TableSourceTable source = scan.getTable().unwrap(TableSourceTable.class);
    final TableConfig tableConfig = unwrapContext(scan).getTableConfig();
    final List<RexNode> projections = new ArrayList<>(project.getProjects());
    if (supportsProjectionPushDown(source.tableSource()) && requiresPrimaryKey(source, tableConfig)) {
        projections.addAll(getPrimaryKeyProjections(scan));
    }
    return projections;
}
Also used : ArrayList(java.util.ArrayList) TableConfig(org.apache.flink.table.api.TableConfig) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) RexNode(org.apache.calcite.rex.RexNode)

Example 38 with TableConfig

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

the class CodeSplitTest method testRecordComparator.

@Test
public void testRecordComparator() {
    int numFields = 600;
    RowType rowType = getIntRowType(numFields);
    SortSpec.SortSpecBuilder builder = SortSpec.builder();
    for (int i = 0; i < numFields; i++) {
        builder.addField(i, true, true);
    }
    SortSpec sortSpec = builder.build();
    GenericRowData rowData1 = new GenericRowData(numFields);
    GenericRowData rowData2 = new GenericRowData(numFields);
    Random random = new Random();
    for (int i = 0; i < numFields; i++) {
        int x = random.nextInt(100);
        rowData1.setField(i, x);
        rowData2.setField(i, x);
    }
    int result = random.nextInt(3) - 1;
    if (result == -1) {
        rowData1.setField(random.nextInt(numFields), -1);
    } else if (result == 1) {
        rowData1.setField(random.nextInt(numFields), 100);
    }
    Consumer<TableConfig> consumer = tableConfig -> {
        RecordComparator instance = ComparatorCodeGenerator.gen(tableConfig, "", rowType, sortSpec).newInstance(classLoader);
        for (int i = 0; i < 100; i++) {
            Assert.assertEquals(result, instance.compare(rowData1, rowData2));
        }
    };
    runTest(consumer);
}
Also used : Arrays(java.util.Arrays) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) IntType(org.apache.flink.table.types.logical.IntType) Random(java.util.Random) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ArrayList(java.util.ArrayList) HashFunction(org.apache.flink.table.runtime.generated.HashFunction) TableConfigOptions(org.apache.flink.table.api.config.TableConfigOptions) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) GenericRowData(org.apache.flink.table.data.GenericRowData) RexNode(org.apache.calcite.rex.RexNode) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RelDataType(org.apache.calcite.rel.type.RelDataType) TableConfig(org.apache.flink.table.api.TableConfig) RecordComparator(org.apache.flink.table.runtime.generated.RecordComparator) RexBuilder(org.apache.calcite.rex.RexBuilder) Test(org.junit.Test) IOException(java.io.IOException) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ComparatorCodeGenerator(org.apache.flink.table.planner.codegen.sort.ComparatorCodeGenerator) RexInputRef(org.apache.calcite.rex.RexInputRef) Consumer(java.util.function.Consumer) JoinUtil(org.apache.flink.table.planner.plan.utils.JoinUtil) JoinCondition(org.apache.flink.table.runtime.generated.JoinCondition) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) LogicalType(org.apache.flink.table.types.logical.LogicalType) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) Assert(org.junit.Assert) Collections(java.util.Collections) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) Projection(org.apache.flink.table.runtime.generated.Projection) Random(java.util.Random) RowType(org.apache.flink.table.types.logical.RowType) GenericRowData(org.apache.flink.table.data.GenericRowData) TableConfig(org.apache.flink.table.api.TableConfig) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) RecordComparator(org.apache.flink.table.runtime.generated.RecordComparator) Test(org.junit.Test)

Example 39 with TableConfig

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

the class CodeSplitTest method testProjection.

@SuppressWarnings("unchecked")
@Test
public void testProjection() {
    int numFields = 1000;
    RowType rowType = getIntRowType(numFields);
    List<Integer> order = new ArrayList<>();
    for (int i = 0; i < numFields; i++) {
        order.add(i);
    }
    Collections.shuffle(order);
    GenericRowData input = new GenericRowData(numFields);
    for (int i = 0; i < numFields; i++) {
        input.setField(i, i);
    }
    BinaryRowData output = new BinaryRowData(numFields);
    BinaryRowWriter outputWriter = new BinaryRowWriter(output);
    for (int i = 0; i < numFields; i++) {
        outputWriter.writeInt(i, order.get(i));
    }
    outputWriter.complete();
    Consumer<TableConfig> consumer = tableConfig -> {
        Projection instance = ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(tableConfig), "", rowType, rowType, order.stream().mapToInt(i -> i).toArray()).newInstance(classLoader);
        for (int i = 0; i < 100; i++) {
            Assert.assertEquals(output, instance.apply(input));
        }
    };
    runTest(consumer);
}
Also used : Arrays(java.util.Arrays) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) IntType(org.apache.flink.table.types.logical.IntType) Random(java.util.Random) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ArrayList(java.util.ArrayList) HashFunction(org.apache.flink.table.runtime.generated.HashFunction) TableConfigOptions(org.apache.flink.table.api.config.TableConfigOptions) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) GenericRowData(org.apache.flink.table.data.GenericRowData) RexNode(org.apache.calcite.rex.RexNode) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RelDataType(org.apache.calcite.rel.type.RelDataType) TableConfig(org.apache.flink.table.api.TableConfig) RecordComparator(org.apache.flink.table.runtime.generated.RecordComparator) RexBuilder(org.apache.calcite.rex.RexBuilder) Test(org.junit.Test) IOException(java.io.IOException) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ComparatorCodeGenerator(org.apache.flink.table.planner.codegen.sort.ComparatorCodeGenerator) RexInputRef(org.apache.calcite.rex.RexInputRef) Consumer(java.util.function.Consumer) JoinUtil(org.apache.flink.table.planner.plan.utils.JoinUtil) JoinCondition(org.apache.flink.table.runtime.generated.JoinCondition) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) LogicalType(org.apache.flink.table.types.logical.LogicalType) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) Assert(org.junit.Assert) Collections(java.util.Collections) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) Projection(org.apache.flink.table.runtime.generated.Projection) ArrayList(java.util.ArrayList) RowType(org.apache.flink.table.types.logical.RowType) Projection(org.apache.flink.table.runtime.generated.Projection) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) GenericRowData(org.apache.flink.table.data.GenericRowData) TableConfig(org.apache.flink.table.api.TableConfig) Test(org.junit.Test)

Example 40 with TableConfig

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

the class LongHashJoinGeneratorTest method newOperator.

@Override
public Object newOperator(long memorySize, HashJoinType type, boolean reverseJoinFunction) {
    RowType keyType = RowType.of(new IntType());
    Assert.assertTrue(LongHashJoinGenerator.support(type, keyType, new boolean[] { true }));
    return LongHashJoinGenerator.gen(new TableConfig(), type, keyType, RowType.of(new IntType(), new IntType()), RowType.of(new IntType(), new IntType()), new int[] { 0 }, new int[] { 0 }, 20, 10000, reverseJoinFunction, new GeneratedJoinCondition(MyJoinCondition.class.getCanonicalName(), "", new Object[0]));
}
Also used : GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig) IntType(org.apache.flink.table.types.logical.IntType)

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