org.apache.flink.table.sources.DefinedProctimeAttribute Java Examples

The following examples show how to use org.apache.flink.table.sources.DefinedProctimeAttribute. 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: ConnectorCatalogTable.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <T1> TableSchema calculateSourceSchema(TableSource<T1> source, boolean isBatch) {
	TableSchema tableSchema = source.getTableSchema();
	if (isBatch) {
		return tableSchema;
	}

	DataType[] types = Arrays.copyOf(tableSchema.getFieldDataTypes(), tableSchema.getFieldCount());
	String[] fieldNames = tableSchema.getFieldNames();
	if (source instanceof DefinedRowtimeAttributes) {
		updateRowtimeIndicators((DefinedRowtimeAttributes) source, fieldNames, types);
	}
	if (source instanceof DefinedProctimeAttribute) {
		updateProctimeIndicator((DefinedProctimeAttribute) source, fieldNames, types);
	}
	return TableSchema.builder().fields(fieldNames, types).build();
}
 
Example #2
Source File: ConnectorCatalogTable.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <T1> TableSchema calculateSourceSchema(TableSource<T1> source, boolean isBatch) {
	TableSchema tableSchema = source.getTableSchema();
	if (isBatch) {
		return tableSchema;
	}

	DataType[] types = Arrays.copyOf(tableSchema.getFieldDataTypes(), tableSchema.getFieldCount());
	String[] fieldNames = tableSchema.getFieldNames();
	if (source instanceof DefinedRowtimeAttributes) {
		updateRowtimeIndicators((DefinedRowtimeAttributes) source, fieldNames, types);
	}
	if (source instanceof DefinedProctimeAttribute) {
		updateProctimeIndicator((DefinedProctimeAttribute) source, fieldNames, types);
	}
	return TableSchema.builder().fields(fieldNames, types).build();
}
 
Example #3
Source File: ConnectorCatalogTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void updateProctimeIndicator(
		DefinedProctimeAttribute source,
		String[] fieldNames,
		DataType[] types) {
	String proctimeAttribute = source.getProctimeAttribute();

	for (int i = 0; i < fieldNames.length; i++) {
		if (fieldNames[i].equals(proctimeAttribute)) {
			// bridged to timestamp for compatible flink-planner
			types[i] = new AtomicDataType(new TimestampType(true, TimestampKind.PROCTIME, 3))
					.bridgedTo(java.sql.Timestamp.class);
			break;
		}
	}
}
 
Example #4
Source File: TypeMappingUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/** Returns the proctime attribute of the [[TableSource]] if it is defined. */
private static Optional<String> getProctimeAttribute(TableSource<?> tableSource) {
	if (tableSource instanceof DefinedProctimeAttribute) {
		return Optional.ofNullable(((DefinedProctimeAttribute) tableSource).getProctimeAttribute());
	} else {
		return Optional.empty();
	}
}
 
Example #5
Source File: ConnectorCatalogTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void updateProctimeIndicator(
		DefinedProctimeAttribute source,
		String[] fieldNames,
		DataType[] types) {
	String proctimeAttribute = source.getProctimeAttribute();

	for (int i = 0; i < fieldNames.length; i++) {
		if (fieldNames[i].equals(proctimeAttribute)) {
			// bridged to timestamp for compatible flink-planner
			types[i] = new AtomicDataType(new TimestampType(true, TimestampKind.PROCTIME, 3))
					.bridgedTo(java.sql.Timestamp.class);
			break;
		}
	}
}