Search in sources :

Example 46 with RowType

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

the class StreamArrowPythonProcTimeBoundedRangeOperatorTest method getTestOperator.

@Override
public AbstractArrowPythonAggregateFunctionOperator getTestOperator(Configuration config, PythonFunctionInfo[] pandasAggregateFunctions, RowType inputType, RowType outputType, int[] groupingSet, int[] udafInputOffsets) {
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputType);
    RowType udfOutputType = (RowType) Projection.range(inputType.getFieldCount(), outputType.getFieldCount()).project(outputType);
    return new PassThroughStreamArrowPythonProcTimeBoundedRangeOperator(config, pandasAggregateFunctions, inputType, udfInputType, udfOutputType, -1, 100L, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "UdafInputProjection", inputType, udfInputType, udafInputOffsets));
}
Also used : RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig)

Example 47 with RowType

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

the class StreamArrowPythonProcTimeBoundedRowsOperatorTest method getTestOperator.

@Override
public AbstractArrowPythonAggregateFunctionOperator getTestOperator(Configuration config, PythonFunctionInfo[] pandasAggregateFunctions, RowType inputType, RowType outputType, int[] groupingSet, int[] udafInputOffsets) {
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputType);
    RowType udfOutputType = (RowType) Projection.range(inputType.getFieldCount(), outputType.getFieldCount()).project(outputType);
    return new PassThroughStreamArrowPythonProcTimeBoundedRowsOperator(config, pandasAggregateFunctions, inputType, udfInputType, udfOutputType, 3, 1, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "UdafInputProjection", inputType, udfInputType, udafInputOffsets));
}
Also used : RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig)

Example 48 with RowType

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

the class PassThroughPythonStreamGroupWindowAggregateOperator method createProjection.

private Projection<RowData, BinaryRowData> createProjection(String name, int[] fields) {
    final RowType forwardedFieldType = new RowType(Arrays.stream(fields).mapToObj(i -> inputType.getFields().get(i)).collect(Collectors.toList()));
    final GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), name, inputType, forwardedFieldType, fields);
    // noinspection unchecked
    return generatedProjection.newInstance(Thread.currentThread().getContextClassLoader());
}
Also used : GeneratedProjection(org.apache.flink.table.runtime.generated.GeneratedProjection) RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig)

Example 49 with RowType

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

the class PythonTypeUtilsTest method testLogicalTypeToProto.

@Test
public void testLogicalTypeToProto() {
    List<RowType.RowField> rowFields = new ArrayList<>();
    rowFields.add(new RowType.RowField("f1", new BigIntType()));
    RowType rowType = new RowType(rowFields);
    FlinkFnApi.Schema.FieldType protoType = rowType.accept(new PythonTypeUtils.LogicalTypeToProtoTypeConverter());
    FlinkFnApi.Schema schema = protoType.getRowSchema();
    assertEquals(1, schema.getFieldsCount());
    assertEquals("f1", schema.getFields(0).getName());
    assertEquals(FlinkFnApi.Schema.TypeName.BIGINT, schema.getFields(0).getType().getTypeName());
}
Also used : FlinkFnApi(org.apache.flink.fnexecution.v1.FlinkFnApi) ArrayList(java.util.ArrayList) RowType(org.apache.flink.table.types.logical.RowType) BigIntType(org.apache.flink.table.types.logical.BigIntType) Test(org.junit.Test)

Example 50 with RowType

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

the class JdbcDynamicTableSource method getScanRuntimeProvider.

@Override
public ScanRuntimeProvider getScanRuntimeProvider(ScanContext runtimeProviderContext) {
    final JdbcRowDataInputFormat.Builder builder = JdbcRowDataInputFormat.builder().setDrivername(options.getDriverName()).setDBUrl(options.getDbURL()).setUsername(options.getUsername().orElse(null)).setPassword(options.getPassword().orElse(null)).setAutoCommit(readOptions.getAutoCommit());
    if (readOptions.getFetchSize() != 0) {
        builder.setFetchSize(readOptions.getFetchSize());
    }
    final JdbcDialect dialect = options.getDialect();
    String query = dialect.getSelectFromStatement(options.getTableName(), DataType.getFieldNames(physicalRowDataType).toArray(new String[0]), new String[0]);
    if (readOptions.getPartitionColumnName().isPresent()) {
        long lowerBound = readOptions.getPartitionLowerBound().get();
        long upperBound = readOptions.getPartitionUpperBound().get();
        int numPartitions = readOptions.getNumPartitions().get();
        builder.setParametersProvider(new JdbcNumericBetweenParametersProvider(lowerBound, upperBound).ofBatchNum(numPartitions));
        query += " WHERE " + dialect.quoteIdentifier(readOptions.getPartitionColumnName().get()) + " BETWEEN ? AND ?";
    }
    if (limit >= 0) {
        query = String.format("%s %s", query, dialect.getLimitClause(limit));
    }
    builder.setQuery(query);
    final RowType rowType = (RowType) physicalRowDataType.getLogicalType();
    builder.setRowConverter(dialect.getRowConverter(rowType));
    builder.setRowDataTypeInfo(runtimeProviderContext.createTypeInformation(physicalRowDataType));
    return InputFormatProvider.of(builder.build());
}
Also used : RowType(org.apache.flink.table.types.logical.RowType) JdbcDialect(org.apache.flink.connector.jdbc.dialect.JdbcDialect) JdbcNumericBetweenParametersProvider(org.apache.flink.connector.jdbc.split.JdbcNumericBetweenParametersProvider)

Aggregations

RowType (org.apache.flink.table.types.logical.RowType)212 RowData (org.apache.flink.table.data.RowData)108 LogicalType (org.apache.flink.table.types.logical.LogicalType)59 DataType (org.apache.flink.table.types.DataType)57 Transformation (org.apache.flink.api.dag.Transformation)50 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)46 TableException (org.apache.flink.table.api.TableException)37 Test (org.junit.Test)36 GenericRowData (org.apache.flink.table.data.GenericRowData)33 ArrayList (java.util.ArrayList)28 List (java.util.List)28 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)26 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)25 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)22 TableConfig (org.apache.flink.table.api.TableConfig)19 ArrayType (org.apache.flink.table.types.logical.ArrayType)19 TimestampType (org.apache.flink.table.types.logical.TimestampType)19 DecimalType (org.apache.flink.table.types.logical.DecimalType)17 Collections (java.util.Collections)16 AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)16