Java Code Examples for org.apache.flink.table.api.TableSchema#getWatermarkSpecs()

The following examples show how to use org.apache.flink.table.api.TableSchema#getWatermarkSpecs() . 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: TableSchemaUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a builder with given table schema.
 *
 * @param oriSchema Original schema
 * @return the builder with all the information from the given schema
 */
public static TableSchema.Builder builderWithGivenSchema(TableSchema oriSchema) {
	TableSchema.Builder builder = builderWithGivenColumns(oriSchema.getTableColumns());
	// Copy watermark specification.
	for (WatermarkSpec wms : oriSchema.getWatermarkSpecs()) {
		builder.watermark(
				wms.getRowtimeAttribute(),
				wms.getWatermarkExpr(),
				wms.getWatermarkExprOutputType());
	}
	// Copy primary key constraint.
	oriSchema.getPrimaryKey()
			.map(pk -> builder.primaryKey(pk.getName(),
					pk.getColumns().toArray(new String[0])));
	return builder;
}
 
Example 2
Source File: TableSchemaUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new schema but drop the constraint with given name.
 */
public static TableSchema dropConstraint(TableSchema oriSchema, String constraintName) {
	// Validate the constraint name is valid.
	Optional<UniqueConstraint> uniqueConstraintOpt = oriSchema.getPrimaryKey();
	if (!uniqueConstraintOpt.isPresent()
			|| !uniqueConstraintOpt.get().getName().equals(constraintName)) {
		throw new ValidationException(
				String.format("Constraint %s to drop does not exist", constraintName));
	}
	TableSchema.Builder builder = builderWithGivenColumns(oriSchema.getTableColumns());
	// Copy watermark specification.
	for (WatermarkSpec wms : oriSchema.getWatermarkSpecs()) {
		builder.watermark(
				wms.getRowtimeAttribute(),
				wms.getWatermarkExpr(),
				wms.getWatermarkExprOutputType());
	}
	return builder.build();
}
 
Example 3
Source File: MergeTableLikeUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private void populateWatermarksFromSourceTable(
		Map<FeatureOption, MergingStrategy> mergingStrategies,
		TableSchema sourceSchema) {
	for (WatermarkSpec sourceWatermarkSpec : sourceSchema.getWatermarkSpecs()) {
		if (mergingStrategies.get(FeatureOption.WATERMARKS) != MergingStrategy.EXCLUDING) {
			watermarkSpecs.put(sourceWatermarkSpec.getRowtimeAttribute(), sourceWatermarkSpec);
		}
	}
}
 
Example 4
Source File: OperationConverterUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void setWatermarkAndPK(TableSchema.Builder builder, TableSchema schema) {
	for (WatermarkSpec watermarkSpec : schema.getWatermarkSpecs()) {
		builder.watermark(watermarkSpec);
	}
	schema.getPrimaryKey().ifPresent(pk -> {
		builder.primaryKey(pk.getName(), pk.getColumns().toArray(new String[0]));
	});
}
 
Example 5
Source File: DescriptorProperties.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a table schema under the given key.
 */
public void putTableSchema(String key, TableSchema schema) {
	checkNotNull(key);
	checkNotNull(schema);

	final String[] fieldNames = schema.getFieldNames();
	final DataType[] fieldTypes = schema.getFieldDataTypes();
	final String[] fieldExpressions = schema.getTableColumns().stream()
		.map(column -> column.getExpr().orElse(null))
		.toArray(String[]::new);

	final List<List<String>> values = new ArrayList<>();
	for (int i = 0; i < schema.getFieldCount(); i++) {
		values.add(
			Arrays.asList(
				fieldNames[i],
				fieldTypes[i].getLogicalType().asSerializableString(),
				fieldExpressions[i]));
	}

	putIndexedOptionalProperties(
		key,
		Arrays.asList(NAME, DATA_TYPE, EXPR),
		values);

	if (!schema.getWatermarkSpecs().isEmpty()) {
		final List<List<String>> watermarkValues = new ArrayList<>();
		for (WatermarkSpec spec : schema.getWatermarkSpecs()) {
			watermarkValues.add(Arrays.asList(
				spec.getRowtimeAttribute(),
				spec.getWatermarkExpr(),
				spec.getWatermarkExprOutputType().getLogicalType().asSerializableString()));
		}
		putIndexedFixedProperties(
			key + '.' + WATERMARK,
			Arrays.asList(WATERMARK_ROWTIME, WATERMARK_STRATEGY_EXPR, WATERMARK_STRATEGY_DATA_TYPE),
			watermarkValues);
	}

	schema.getPrimaryKey().ifPresent(pk -> {
		putString(key + '.' + PRIMARY_KEY_NAME, pk.getName());
		putString(key + '.' + PRIMARY_KEY_COLUMNS, String.join(",", pk.getColumns()));
	});
}