Java Code Examples for org.apache.flink.table.types.logical.RowType#of()

The following examples show how to use org.apache.flink.table.types.logical.RowType#of() . 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: KeySelectorUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Create a BaseRowKeySelector to extract keys from DataStream which type is BaseRowTypeInfo.
 *
 * @param keyFields key fields
 * @param rowType type of DataStream to extract keys
 * @return the BaseRowKeySelector to extract keys from DataStream which type is BaseRowTypeInfo.
 */
public static BaseRowKeySelector getBaseRowSelector(int[] keyFields, BaseRowTypeInfo rowType) {
	if (keyFields.length > 0) {
		LogicalType[] inputFieldTypes = rowType.getLogicalTypes();
		String[] inputFieldNames = rowType.getFieldNames();
		LogicalType[] keyFieldTypes = new LogicalType[keyFields.length];
		String[] keyFieldNames = new String[keyFields.length];
		for (int i = 0; i < keyFields.length; ++i) {
			keyFieldTypes[i] = inputFieldTypes[keyFields[i]];
			keyFieldNames[i] = inputFieldNames[keyFields[i]];
		}
		RowType returnType = RowType.of(keyFieldTypes, keyFieldNames);
		RowType inputType = RowType.of(inputFieldTypes, rowType.getFieldNames());
		GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(
			CodeGeneratorContext.apply(new TableConfig()),
			"KeyProjection",
			inputType,
			returnType, keyFields);
		BaseRowTypeInfo keyRowType = BaseRowTypeInfo.of(returnType);
		return new BinaryRowKeySelector(keyRowType, generatedProjection);
	} else {
		return NullBinaryRowKeySelector.INSTANCE;
	}
}
 
Example 2
Source File: LongHashJoinGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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},
			memorySize, memorySize, 0, 20, 10000,
			reverseJoinFunction,
			new GeneratedJoinCondition(MyJoinCondition.class.getCanonicalName(), "", new Object[0])
	);
}
 
Example 3
Source File: JdbcRowDataLookupFunctionTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private JdbcRowDataLookupFunction buildRowDataLookupFunction() {
	JdbcOptions jdbcOptions = JdbcOptions.builder()
		.setDriverName(DERBY_EBOOKSHOP_DB.getDriverClass())
		.setDBUrl(DB_URL)
		.setTableName(LOOKUP_TABLE)
		.build();

	JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().build();

	RowType rowType = RowType.of(Arrays.stream(fieldDataTypes).
		map(DataType::getLogicalType).toArray(LogicalType[]::new), fieldNames);

	JdbcRowDataLookupFunction lookupFunction = new JdbcRowDataLookupFunction(
		jdbcOptions,
		lookupOptions,
		fieldNames,
		fieldDataTypes,
		lookupKeys,
		rowType);

	return lookupFunction;
}
 
Example 4
Source File: HiveTableSink.java    From flink with Apache License 2.0 6 votes vote down vote up
private Optional<BulkWriter.Factory<RowData>> createBulkWriterFactory(String[] partitionColumns,
		StorageDescriptor sd) {
	String serLib = sd.getSerdeInfo().getSerializationLib().toLowerCase();
	int formatFieldCount = tableSchema.getFieldCount() - partitionColumns.length;
	String[] formatNames = new String[formatFieldCount];
	LogicalType[] formatTypes = new LogicalType[formatFieldCount];
	for (int i = 0; i < formatFieldCount; i++) {
		formatNames[i] = tableSchema.getFieldName(i).get();
		formatTypes[i] = tableSchema.getFieldDataType(i).get().getLogicalType();
	}
	RowType formatType = RowType.of(formatTypes, formatNames);
	Configuration formatConf = new Configuration(jobConf);
	sd.getSerdeInfo().getParameters().forEach(formatConf::set);
	if (serLib.contains("parquet")) {
		return Optional.of(ParquetRowDataBuilder.createWriterFactory(
				formatType, formatConf, hiveVersion.startsWith("3.")));
	} else if (serLib.contains("orc")) {
		TypeDescription typeDescription = OrcSplitReaderUtil.logicalTypeToOrcType(formatType);
		return Optional.of(hiveShim.createOrcBulkWriterFactory(
				formatConf, typeDescription.toString(), formatTypes));
	} else {
		return Optional.empty();
	}
}
 
Example 5
Source File: KeySelectorUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Create a RowDataKeySelector to extract keys from DataStream which type is RowDataTypeInfo.
 *
 * @param keyFields key fields
 * @param rowType type of DataStream to extract keys
 * @return the RowDataKeySelector to extract keys from DataStream which type is RowDataTypeInfo.
 */
public static RowDataKeySelector getRowDataSelector(int[] keyFields, RowDataTypeInfo rowType) {
	if (keyFields.length > 0) {
		LogicalType[] inputFieldTypes = rowType.getLogicalTypes();
		LogicalType[] keyFieldTypes = new LogicalType[keyFields.length];
		for (int i = 0; i < keyFields.length; ++i) {
			keyFieldTypes[i] = inputFieldTypes[keyFields[i]];
		}
		// do not provide field names for the result key type,
		// because we may have duplicate key fields and the field names may conflict
		RowType returnType = RowType.of(keyFieldTypes);
		RowType inputType = rowType.toRowType();
		GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(
			CodeGeneratorContext.apply(new TableConfig()),
			"KeyProjection",
			inputType,
			returnType,
			keyFields);
		RowDataTypeInfo keyRowType = RowDataTypeInfo.of(returnType);
		return new BinaryRowDataKeySelector(keyRowType, generatedProjection);
	} else {
		return EmptyRowDataKeySelector.INSTANCE;
	}
}
 
Example 6
Source File: LongHashJoinGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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])
	);
}
 
Example 7
Source File: PlannerTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static RowType toRowType(LogicalType t) {
	if (t instanceof RowType) {
		return (RowType) t;
	} else {
		return RowType.of(t);
	}
}
 
Example 8
Source File: RexNodeConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private RexNode convertRow(List<Expression> children) {
	// TODO get type from CallExpression directly
	List<RexNode> childrenRexNode = convertCallChildren(children);
	LogicalType[] childTypes = childrenRexNode.stream().map(rexNode -> toLogicalType(rexNode.getType()))
			.toArray(LogicalType[]::new);
	RowType rowType = RowType.of(childTypes);
	RelDataType relDataType = typeFactory.createFieldTypeFromLogicalType(rowType);
	return relBuilder.getRexBuilder().makeCall(relDataType, FlinkSqlOperatorTable.ROW, childrenRexNode);
}
 
Example 9
Source File: PlannerTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static RowType toRowType(LogicalType t) {
	if (t instanceof RowType) {
		return (RowType) t;
	} else {
		return RowType.of(t);
	}
}
 
Example 10
Source File: FileSystemFormatFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * RowType of table that excludes partition key fields.
 */
default RowType getFormatRowType() {
	return RowType.of(
		Arrays.stream(getFormatFieldTypes())
			.map(DataType::getLogicalType)
			.toArray(LogicalType[]::new),
		getFormatFieldNames());
}
 
Example 11
Source File: FileSystemFormatFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Get RowType of the table without partition keys.
 * @return
 */
default RowType getFormatRowType() {
	return RowType.of(
		Arrays.stream(getFormatFieldTypes())
			.map(DataType::getLogicalType)
			.toArray(LogicalType[]::new),
		getFormatFieldNames());
}
 
Example 12
Source File: BaseRowTypeInfo.java    From flink with Apache License 2.0 4 votes vote down vote up
public RowType toRowType() {
	return RowType.of(logicalTypes, fieldNames);
}
 
Example 13
Source File: RowDataTypeInfo.java    From flink with Apache License 2.0 4 votes vote down vote up
public RowType toRowType() {
	return RowType.of(logicalTypes, fieldNames);
}