Example #1
0
 def _to_data_type(field):
     if field.type.type_name == flink_fn_execution_pb2.Schema.TINYINT:
         return TinyIntType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.SMALLINT:
         return SmallIntType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.INT:
         return IntType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.BIGINT:
         return BigIntType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.BOOLEAN:
         return BooleanType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.FLOAT:
         return FloatType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.DOUBLE:
         return DoubleType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.VARCHAR:
         return VarCharType(0x7fffffff, field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.VARBINARY:
         return VarBinaryType(0x7fffffff, field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.DECIMAL:
         return DecimalType(field.type.decimal_info.precision,
                            field.type.decimal_info.scale,
                            field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.DATE:
         return DateType(field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.TIME:
         return TimeType(field.type.time_info.precision, field.type.nullable)
     elif field.type.type_name == \
             flink_fn_execution_pb2.Schema.LOCAL_ZONED_TIMESTAMP:
         return LocalZonedTimestampType(field.type.local_zoned_timestamp_info.precision,
                                        field.type.nullable)
     elif field.type.type_name == flink_fn_execution_pb2.Schema.TIMESTAMP:
         return TimestampType(field.type.timestamp_info.precision, field.type.nullable)
     else:
         raise ValueError("field_type %s is not supported." % field.type)
Example #2
0
    def _to_data_type(cls, field_type):
        from pyflink.fn_execution import flink_fn_execution_pb2

        if field_type.type_name == flink_fn_execution_pb2.Schema.TINYINT:
            return TinyIntType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.SMALLINT:
            return SmallIntType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.INT:
            return IntType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.BIGINT:
            return BigIntType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.BOOLEAN:
            return BooleanType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.FLOAT:
            return FloatType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.DOUBLE:
            return DoubleType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.VARCHAR:
            return VarCharType(0x7fffffff, field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.VARBINARY:
            return VarBinaryType(0x7fffffff, field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.DECIMAL:
            return DecimalType(field_type.decimal_info.precision,
                               field_type.decimal_info.scale,
                               field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.DATE:
            return DateType(field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.TIME:
            return TimeType(field_type.time_info.precision,
                            field_type.nullable)
        elif field_type.type_name == \
                flink_fn_execution_pb2.Schema.LOCAL_ZONED_TIMESTAMP:
            return LocalZonedTimestampType(
                field_type.local_zoned_timestamp_info.precision,
                field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.TIMESTAMP:
            return TimestampType(field_type.timestamp_info.precision,
                                 field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.BASIC_ARRAY:
            return ArrayType(
                cls._to_data_type(field_type.collection_element_type),
                field_type.nullable)
        elif field_type.type_name == flink_fn_execution_pb2.Schema.TypeName.ROW:
            return RowType([
                RowField(f.name, cls._to_data_type(f.type), f.description)
                for f in field_type.row_schema.fields
            ], field_type.nullable)
        else:
            raise ValueError("field_type %s is not supported." % field_type)