Java Code Examples for org.apache.flink.table.types.logical.LogicalTypeRoot#ROW
The following examples show how to use
org.apache.flink.table.types.logical.LogicalTypeRoot#ROW .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseTableSchema.java From flink with Apache License 2.0 | 6 votes |
/** * Construct a {@link HBaseTableSchema} from a {@link TableSchema}. */ public static HBaseTableSchema fromTableSchema(TableSchema schema) { HBaseTableSchema hbaseSchema = new HBaseTableSchema(); RowType rowType = (RowType) schema.toPhysicalRowDataType().getLogicalType(); for (RowType.RowField field : rowType.getFields()) { LogicalType fieldType = field.getType(); if (fieldType.getTypeRoot() == LogicalTypeRoot.ROW) { RowType familyType = (RowType) fieldType; String familyName = field.getName(); for (RowType.RowField qualifier : familyType.getFields()) { hbaseSchema.addColumn( familyName, qualifier.getName(), fromLogicalToDataType(qualifier.getType())); } } else if (fieldType.getChildren().size() == 0) { hbaseSchema.setRowKey(field.getName(), fromLogicalToDataType(fieldType)); } else { throw new IllegalArgumentException( "Unsupported field type '" + fieldType + "' for HBase."); } } return hbaseSchema; }
Example 2
Source File: DataTypePrecisionFixer.java From flink with Apache License 2.0 | 6 votes |
@Override public DataType visit(FieldsDataType fieldsDataType) { final List<DataType> fieldDataTypes = fieldsDataType.getChildren(); if (logicalType.getTypeRoot() == LogicalTypeRoot.ROW) { final List<String> fieldNames = getFieldNames(logicalType); DataTypes.Field[] fields = IntStream.range(0, fieldDataTypes.size()) .mapToObj(i -> { final DataType oldFieldType = fieldDataTypes.get(i); final DataType newFieldType = oldFieldType.accept( new DataTypePrecisionFixer(logicalType.getChildren().get(i))); return DataTypes.FIELD(fieldNames.get(i), newFieldType); }) .toArray(DataTypes.Field[]::new); return DataTypes.ROW(fields).bridgedTo(fieldsDataType.getConversionClass()); } throw new UnsupportedOperationException("Unsupported logical type : " + logicalType); }
Example 3
Source File: CsvRowSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
/** * Convert {@link LogicalType} to {@link CsvSchema.ColumnType} based on Jackson's categories. */ private static CsvSchema.ColumnType convertType(String fieldName, LogicalType type) { if (STRING_TYPE_ROOTS.contains(type.getTypeRoot())) { return CsvSchema.ColumnType.STRING; } else if (NUMBER_TYPE_ROOTS.contains(type.getTypeRoot())) { return CsvSchema.ColumnType.NUMBER; } else if (BOOLEAN_TYPE_ROOTS.contains(type.getTypeRoot())) { return CsvSchema.ColumnType.BOOLEAN; } else if (type.getTypeRoot() == LogicalTypeRoot.ARRAY) { validateNestedField(fieldName, ((ArrayType) type).getElementType()); return CsvSchema.ColumnType.ARRAY; } else if (type.getTypeRoot() == LogicalTypeRoot.ROW) { RowType rowType = (RowType) type; for (LogicalType fieldType : rowType.getChildren()) { validateNestedField(fieldName, fieldType); } return CsvSchema.ColumnType.ARRAY; } else { throw new IllegalArgumentException( "Unsupported type '" + type.asSummaryString() + "' for field '" + fieldName + "'."); } }
Example 4
Source File: LogicalTypeChecks.java From flink with Apache License 2.0 | 3 votes |
/** * Checks if the given type is a composite type. * * <p>Use {@link #getFieldCount(LogicalType)}, {@link #getFieldNames(LogicalType)}, * {@link #getFieldTypes(LogicalType)} for unified handling of composite types. * * @param logicalType Logical data type to check * @return True if the type is composite type. */ public static boolean isCompositeType(LogicalType logicalType) { if (logicalType instanceof DistinctType) { return isCompositeType(((DistinctType) logicalType).getSourceType()); } LogicalTypeRoot typeRoot = logicalType.getTypeRoot(); return typeRoot == LogicalTypeRoot.STRUCTURED_TYPE || typeRoot == LogicalTypeRoot.ROW; }