Java Code Examples for org.apache.beam.sdk.schemas.Schema#LogicalType

The following examples show how to use org.apache.beam.sdk.schemas.Schema#LogicalType . 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: SchemaUtil.java    From beam with Apache License 2.0 6 votes vote down vote up
/** Creates a {@link ResultSetFieldExtractor} for logical types. */
private static <InputT, BaseT> ResultSetFieldExtractor createLogicalTypeExtractor(
    final Schema.LogicalType<InputT, BaseT> fieldType) {
  String logicalTypeName = fieldType.getIdentifier();
  JDBCType underlyingType = JDBCType.valueOf(logicalTypeName);
  switch (underlyingType) {
    case DATE:
      return DATE_EXTRACTOR;
    case TIME:
      return TIME_EXTRACTOR;
    case TIMESTAMP_WITH_TIMEZONE:
      return TIMESTAMP_EXTRACTOR;
    default:
      ResultSetFieldExtractor extractor = createFieldExtractor(fieldType.getBaseType());
      return (rs, index) -> fieldType.toInputType((BaseT) extractor.extract(rs, index));
  }
}
 
Example 2
Source File: ProtoDynamicMessageSchema.java    From beam with Apache License 2.0 5 votes vote down vote up
OneOfConvert(
    ProtoDynamicMessageSchema protoSchema, Schema.Field field, Schema.LogicalType logicalType) {
  super(field);
  this.logicalType = (OneOfType) logicalType;
  for (Schema.Field oneOfField : this.logicalType.getOneOfSchema().getFields()) {
    int fieldNumber = getFieldNumber(oneOfField);
    oneOfConvert.put(
        fieldNumber,
        new NullableConvert(
            oneOfField, protoSchema.createConverter(oneOfField.withNullable(false))));
  }
}
 
Example 3
Source File: SchemaUtil.java    From beam with Apache License 2.0 5 votes vote down vote up
/** Converts logical types with arguments such as VARCHAR(25). */
private static <InputT, BaseT> BeamFieldConverter beamLogicalField(
    String identifier,
    BiFunction<String, Integer, Schema.LogicalType<InputT, BaseT>> constructor) {
  return (index, md) -> {
    int size = md.getPrecision(index);
    Schema.FieldType fieldType =
        Schema.FieldType.logicalType(constructor.apply(identifier, size));
    return beamFieldOfType(fieldType).create(index, md);
  };
}
 
Example 4
Source File: ProtoDynamicMessageSchema.java    From beam with Apache License 2.0 4 votes vote down vote up
EnumConvert(Schema.Field field, Schema.LogicalType logicalType) {
  super(field);
  this.logicalType = (EnumerationType) logicalType;
}
 
Example 5
Source File: ProtoDynamicMessageSchema.java    From beam with Apache License 2.0 4 votes vote down vote up
LogicalTypeConvert(Schema.Field field, Schema.LogicalType logicalType) {
  super(field);
  this.logicalType = logicalType;
}