Java Code Examples for org.apache.flink.table.api.Types#SQL_TIMESTAMP

The following examples show how to use org.apache.flink.table.api.Types#SQL_TIMESTAMP . 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: KafkaTableSourceBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a list of fields to be rowtime attributes.
 *
 * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes.
 */
private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) {
	Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null.");
	// validate that all declared fields exist and are of correct type
	for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) {
		String rowtimeAttribute = desc.getAttributeName();
		Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute);
		if (!tpe.isPresent()) {
			throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema.");
		} else if (tpe.get() != Types.SQL_TIMESTAMP()) {
			throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP.");
		}
	}
	return rowtimeAttributeDescriptors;
}
 
Example 2
Source File: PulsarTableSource.java    From pulsar-flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a list of fields to be rowtime attributes.
 *
 * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes.
 */
private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) {
    Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null.");
    // validate that all declared fields exist and are of correct type
    for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) {
        String rowtimeAttribute = desc.getAttributeName();
        Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute);
        if (!tpe.isPresent()) {
            throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema.");
        } else if (tpe.get() != Types.SQL_TIMESTAMP()) {
            throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP.");
        }
    }
    return rowtimeAttributeDescriptors;
}
 
Example 3
Source File: KafkaTableSourceBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a list of fields to be rowtime attributes.
 *
 * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes.
 */
private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) {
	Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null.");
	// validate that all declared fields exist and are of correct type
	for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) {
		String rowtimeAttribute = desc.getAttributeName();
		Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute);
		if (!tpe.isPresent()) {
			throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema.");
		} else if (tpe.get() != Types.SQL_TIMESTAMP()) {
			throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP.");
		}
	}
	return rowtimeAttributeDescriptors;
}
 
Example 4
Source File: KafkaBaseSinkDescriptor.java    From alchemy with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T transform(TableSchema param) throws Exception {
    TableSchema tableSchema = createTableSchema();
    if (tableSchema == null) {
        tableSchema = param;
    }
    if (tableSchema == null) {
        throw new IllegalArgumentException("TableSchema must be not null");
    }
    TypeInformation[] fieldTypes = new TypeInformation[tableSchema.getFieldCount()];
    for (int i = 0; i < tableSchema.getFieldCount(); i++) {
        if (FlinkTypeFactory.isTimeIndicatorType(tableSchema.getFieldTypes()[i])) {
            fieldTypes[i] = Types.SQL_TIMESTAMP();
        }else{
            fieldTypes[i] = tableSchema.getFieldTypes()[i];
        }
    }
    TypeInformation typeInformation = new RowTypeInfo(fieldTypes, tableSchema.getFieldNames());
    SerializationSchema<Row> rowSerializationSchema = createSerializationSchema(typeInformation);
    return (T) newTableSink(
        new TableSchema(tableSchema.getFieldNames(), fieldTypes),
        this.topic,
        PropertiesUtil.fromYamlMap(this.getProperties()),
        Optional.empty(),
        rowSerializationSchema == null ? new JsonRowSerializationSchema(typeInformation) : rowSerializationSchema
    );
}
 
Example 5
Source File: FlinkSqlTextBusiness.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
private static TypeInformation[] convertStringToType(String[] dataTypeStrArray) throws FlinkSqlException {

        TypeInformation[] dataTypeArray = new TypeInformation[dataTypeStrArray.length];


        for(int i = 0;i< dataTypeStrArray.length;i++){

            String type = dataTypeStrArray[i];

            if("string".equals(type)){
                dataTypeArray[i] = Types.STRING();
            }
            else if("short".equals(type)){
                dataTypeArray[i] = Types.SHORT();
            }
            else if("int".equals(type)){
                dataTypeArray[i] = Types.INT();
            }
            else if("long".equals(type)){
                dataTypeArray[i] = Types.LONG();
            }
            else if("date".equals(type)){
                dataTypeArray[i] = Types.SQL_DATE();
            }
            else if("timestamp".equals(type)){
                dataTypeArray[i] = Types.SQL_TIMESTAMP();
            }
            else if("float".equals(type)){
                dataTypeArray[i] = Types.FLOAT();
            }
            else if("double".equals(type)){
                dataTypeArray[i] = Types.DOUBLE();
            }
            else if("byte".equals(type)){
                dataTypeArray[i] = Types.BYTE();
            }
            else{
                throw new FlinkSqlException("类型错误["+dataTypeArray[i]+"]");
            }
        }

        return dataTypeArray;

    }