Search in sources :

Example 11 with IntType

use of org.apache.flink.table.types.logical.IntType in project flink by apache.

the class DataTypeExtractorTest method getComplexPojoDataType.

/**
 * Testing data type shared with the Scala tests.
 */
static DataType getComplexPojoDataType(Class<?> complexPojoClass, Class<?> simplePojoClass) {
    final StructuredType.Builder builder = StructuredType.newBuilder(complexPojoClass);
    builder.attributes(Arrays.asList(new StructuredAttribute("mapField", new MapType(VarCharType.STRING_TYPE, new IntType())), new StructuredAttribute("simplePojoField", getSimplePojoDataType(simplePojoClass).getLogicalType()), new StructuredAttribute("someObject", dummyRaw(Object.class).getLogicalType())));
    builder.setFinal(true);
    builder.setInstantiable(true);
    final StructuredType structuredType = builder.build();
    final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.MAP(DataTypes.STRING(), DataTypes.INT()), getSimplePojoDataType(simplePojoClass), dummyRaw(Object.class));
    return new FieldsDataType(structuredType, complexPojoClass, fieldDataTypes);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) MapType(org.apache.flink.table.types.logical.MapType) StructuredType(org.apache.flink.table.types.logical.StructuredType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType)

Example 12 with IntType

use of org.apache.flink.table.types.logical.IntType in project flink by apache.

the class DataTypeExtractorTest method getOuterTupleDataType.

private static DataType getOuterTupleDataType() {
    final StructuredType.Builder builder = StructuredType.newBuilder(Tuple2.class);
    builder.attributes(Arrays.asList(new StructuredAttribute("f0", new IntType()), new StructuredAttribute("f1", getInnerTupleDataType().getLogicalType())));
    builder.setFinal(true);
    builder.setInstantiable(true);
    final StructuredType structuredType = builder.build();
    final List<DataType> fieldDataTypes = Arrays.asList(DataTypes.INT(), getInnerTupleDataType());
    return new FieldsDataType(structuredType, Tuple2.class, fieldDataTypes);
}
Also used : FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) DataType(org.apache.flink.table.types.DataType) FieldsDataType(org.apache.flink.table.types.FieldsDataType) StructuredType(org.apache.flink.table.types.logical.StructuredType) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType)

Example 13 with IntType

use of org.apache.flink.table.types.logical.IntType in project flink by apache.

the class WindowOperatorContractTest method createWindowOperator.

// ------------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
private <W extends Window> KeyedOneInputStreamOperatorTestHarness<RowData, RowData, RowData> createWindowOperator(WindowAssigner<W> assigner, Trigger<W> trigger, NamespaceAggsHandleFunctionBase<W> aggregationsFunction, long allowedLateness) throws Exception {
    LogicalType[] inputTypes = new LogicalType[] { VarCharType.STRING_TYPE, new IntType() };
    RowDataKeySelector keySelector = HandwrittenSelectorUtil.getRowDataSelector(new int[] { 0 }, inputTypes);
    TypeInformation<RowData> keyType = keySelector.getProducedType();
    LogicalType[] accTypes = new LogicalType[] { new BigIntType(), new BigIntType() };
    LogicalType[] windowTypes = new LogicalType[] { new BigIntType(), new BigIntType() };
    LogicalType[] outputTypeWithoutKeys = new LogicalType[] { new BigIntType(), new BigIntType(), new BigIntType(), new BigIntType() };
    boolean sendRetraction = allowedLateness > 0;
    if (aggregationsFunction instanceof NamespaceAggsHandleFunction) {
        AggregateWindowOperator operator = new AggregateWindowOperator((NamespaceAggsHandleFunction) aggregationsFunction, mock(RecordEqualiser.class), assigner, trigger, assigner.getWindowSerializer(new ExecutionConfig()), inputTypes, outputTypeWithoutKeys, accTypes, windowTypes, 2, sendRetraction, allowedLateness, UTC_ZONE_ID, -1);
        return new KeyedOneInputStreamOperatorTestHarness<RowData, RowData, RowData>(operator, keySelector, keyType);
    } else {
        TableAggregateWindowOperator operator = new TableAggregateWindowOperator((NamespaceTableAggsHandleFunction) aggregationsFunction, assigner, trigger, assigner.getWindowSerializer(new ExecutionConfig()), inputTypes, outputTypeWithoutKeys, accTypes, windowTypes, 2, sendRetraction, allowedLateness, UTC_ZONE_ID, -1);
        return new KeyedOneInputStreamOperatorTestHarness<RowData, RowData, RowData>(operator, keySelector, keyType);
    }
}
Also used : RecordEqualiser(org.apache.flink.table.runtime.generated.RecordEqualiser) LogicalType(org.apache.flink.table.types.logical.LogicalType) BigIntType(org.apache.flink.table.types.logical.BigIntType) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) NamespaceAggsHandleFunction(org.apache.flink.table.runtime.generated.NamespaceAggsHandleFunction) KeyedOneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness) IntType(org.apache.flink.table.types.logical.IntType) BigIntType(org.apache.flink.table.types.logical.BigIntType) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector)

Example 14 with IntType

use of org.apache.flink.table.types.logical.IntType in project flink by apache.

the class RowTimeSortOperatorTest method testSortOnTwoFields.

@Test
public void testSortOnTwoFields() throws Exception {
    InternalTypeInfo<RowData> inputRowType = InternalTypeInfo.ofFields(new IntType(), new BigIntType(), VarCharType.STRING_TYPE, new IntType());
    // Note: RowTimeIdx must be 0 in product environment, the value is 1 here just for simplify
    // the testing
    int rowTimeIdx = 1;
    GeneratedRecordComparator gComparator = new GeneratedRecordComparator("", "", new Object[0]) {

        private static final long serialVersionUID = -6067266199060901331L;

        @Override
        public RecordComparator newInstance(ClassLoader classLoader) {
            return IntRecordComparator.INSTANCE;
        }
    };
    RowDataHarnessAssertor assertor = new RowDataHarnessAssertor(inputRowType.toRowFieldTypes());
    RowTimeSortOperator operator = createSortOperator(inputRowType, rowTimeIdx, gComparator);
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(operator);
    testHarness.open();
    testHarness.processElement(insertRecord(3, 3L, "Hello world", 3));
    testHarness.processElement(insertRecord(2, 2L, "Hello", 2));
    testHarness.processElement(insertRecord(6, 2L, "Luke Skywalker", 6));
    testHarness.processElement(insertRecord(5, 3L, "I am fine.", 5));
    testHarness.processElement(insertRecord(7, 1L, "Comment#1", 7));
    testHarness.processElement(insertRecord(9, 4L, "Comment#3", 9));
    testHarness.processElement(insertRecord(10, 4L, "Comment#4", 10));
    testHarness.processElement(insertRecord(8, 4L, "Comment#2", 8));
    testHarness.processElement(insertRecord(1, 1L, "Hi", 2));
    testHarness.processElement(insertRecord(1, 1L, "Hi", 1));
    testHarness.processElement(insertRecord(4, 3L, "Helloworld, how are you?", 4));
    testHarness.processElement(insertRecord(4, 5L, "Hello, how are you?", 4));
    testHarness.processWatermark(new Watermark(4L));
    List<Object> expectedOutput = new ArrayList<>();
    expectedOutput.add(insertRecord(1, 1L, "Hi", 2));
    expectedOutput.add(insertRecord(1, 1L, "Hi", 1));
    expectedOutput.add(insertRecord(7, 1L, "Comment#1", 7));
    expectedOutput.add(insertRecord(2, 2L, "Hello", 2));
    expectedOutput.add(insertRecord(6, 2L, "Luke Skywalker", 6));
    expectedOutput.add(insertRecord(3, 3L, "Hello world", 3));
    expectedOutput.add(insertRecord(4, 3L, "Helloworld, how are you?", 4));
    expectedOutput.add(insertRecord(5, 3L, "I am fine.", 5));
    expectedOutput.add(insertRecord(8, 4L, "Comment#2", 8));
    expectedOutput.add(insertRecord(9, 4L, "Comment#3", 9));
    expectedOutput.add(insertRecord(10, 4L, "Comment#4", 10));
    expectedOutput.add(new Watermark(4L));
    // do a snapshot, data could be recovered from state
    OperatorSubtaskState snapshot = testHarness.snapshot(0L, 0);
    assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
    testHarness.close();
    expectedOutput.clear();
    operator = createSortOperator(inputRowType, rowTimeIdx, gComparator);
    testHarness = createTestHarness(operator);
    testHarness.initializeState(snapshot);
    testHarness.open();
    // late data will be dropped
    testHarness.processElement(insertRecord(5, 3L, "I am fine.", 6));
    testHarness.processWatermark(new Watermark(5L));
    expectedOutput.add(insertRecord(4, 5L, "Hello, how are you?", 4));
    expectedOutput.add(new Watermark(5L));
    assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
    // those watermark has no effect
    testHarness.processWatermark(new Watermark(11L));
    testHarness.processWatermark(new Watermark(12L));
    expectedOutput.add(new Watermark(11L));
    expectedOutput.add(new Watermark(12L));
    assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
}
Also used : ArrayList(java.util.ArrayList) BigIntType(org.apache.flink.table.types.logical.BigIntType) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) BigIntType(org.apache.flink.table.types.logical.BigIntType) IntType(org.apache.flink.table.types.logical.IntType) RowData(org.apache.flink.table.data.RowData) RowDataHarnessAssertor(org.apache.flink.table.runtime.util.RowDataHarnessAssertor) GeneratedRecordComparator(org.apache.flink.table.runtime.generated.GeneratedRecordComparator) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 15 with IntType

use of org.apache.flink.table.types.logical.IntType in project flink by apache.

the class RandomSortMergeInnerJoinTest method join.

public static LinkedBlockingQueue<Object> join(StreamOperator operator, MutableObjectIterator<Tuple2<Integer, String>> input1, MutableObjectIterator<Tuple2<Integer, String>> input2, boolean input1First) throws Exception {
    InternalTypeInfo<RowData> typeInfo = InternalTypeInfo.ofFields(new IntType(), VarCharType.STRING_TYPE);
    InternalTypeInfo<RowData> joinedInfo = InternalTypeInfo.ofFields(new IntType(), VarCharType.STRING_TYPE, new IntType(), VarCharType.STRING_TYPE);
    final TwoInputStreamTaskTestHarness<BinaryRowData, BinaryRowData, JoinedRowData> testHarness = new TwoInputStreamTaskTestHarness<>(TwoInputStreamTask::new, 2, 1, new int[] { 1, 2 }, typeInfo, (TypeInformation) typeInfo, joinedInfo);
    // Deep pit!!! Cause in TwoInputStreamTaskTestHarness, one record one buffer.
    testHarness.bufferSize = 10 * 1024;
    testHarness.getExecutionConfig().enableObjectReuse();
    testHarness.memorySize = 36 * 1024 * 1024;
    testHarness.setupOutputForSingletonOperatorChain();
    testHarness.getStreamConfig().setStreamOperator(operator);
    testHarness.getStreamConfig().setOperatorID(new OperatorID());
    testHarness.getStreamConfig().setManagedMemoryFractionOperatorOfUseCase(ManagedMemoryUseCase.OPERATOR, 0.99);
    long initialTime = 0L;
    testHarness.invoke();
    testHarness.waitForTaskRunning();
    if (input1First) {
        Tuple2<Integer, String> tuple2 = new Tuple2<>();
        while ((tuple2 = input1.next(tuple2)) != null) {
            testHarness.processElement(new StreamRecord<>(newRow(tuple2.f0, tuple2.f1), initialTime), 0, 0);
        }
        testHarness.waitForInputProcessing();
        tuple2 = new Tuple2<>();
        while ((tuple2 = input2.next(tuple2)) != null) {
            testHarness.processElement(new StreamRecord<>(newRow(tuple2.f0, tuple2.f1), initialTime), 1, 0);
        }
        testHarness.waitForInputProcessing();
    } else {
        Tuple2<Integer, String> tuple2 = new Tuple2<>();
        while ((tuple2 = input2.next(tuple2)) != null) {
            testHarness.processElement(new StreamRecord<>(newRow(tuple2.f0, tuple2.f1), initialTime), 1, 0);
        }
        testHarness.waitForInputProcessing();
        tuple2 = new Tuple2<>();
        while ((tuple2 = input1.next(tuple2)) != null) {
            testHarness.processElement(new StreamRecord<>(newRow(tuple2.f0, tuple2.f1), initialTime), 0, 0);
        }
        testHarness.waitForInputProcessing();
    }
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
    return testHarness.getOutput();
}
Also used : OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) TwoInputStreamTaskTestHarness(org.apache.flink.streaming.runtime.tasks.TwoInputStreamTaskTestHarness) IntType(org.apache.flink.table.types.logical.IntType) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) TwoInputStreamTask(org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) Tuple2(org.apache.flink.api.java.tuple.Tuple2) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData)

Aggregations

IntType (org.apache.flink.table.types.logical.IntType)43 BigIntType (org.apache.flink.table.types.logical.BigIntType)23 LogicalType (org.apache.flink.table.types.logical.LogicalType)18 RowData (org.apache.flink.table.data.RowData)13 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 GenericRowData (org.apache.flink.table.data.GenericRowData)10 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)10 DoubleType (org.apache.flink.table.types.logical.DoubleType)10 SmallIntType (org.apache.flink.table.types.logical.SmallIntType)10 TimestampType (org.apache.flink.table.types.logical.TimestampType)10 TinyIntType (org.apache.flink.table.types.logical.TinyIntType)10 VarCharType (org.apache.flink.table.types.logical.VarCharType)10 BooleanType (org.apache.flink.table.types.logical.BooleanType)8 DecimalType (org.apache.flink.table.types.logical.DecimalType)7 MapType (org.apache.flink.table.types.logical.MapType)7 RowType (org.apache.flink.table.types.logical.RowType)7 StructuredType (org.apache.flink.table.types.logical.StructuredType)7 DataType (org.apache.flink.table.types.DataType)6 FloatType (org.apache.flink.table.types.logical.FloatType)6