org.apache.flink.table.types.logical.DateType Java Examples

The following examples show how to use org.apache.flink.table.types.logical.DateType. 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: SqlDateTimeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static long convertExtract(TimeUnitRange range, long ts, LogicalType type, TimeZone tz) {
	TimeUnit startUnit = range.startUnit;
	long offset = tz.getOffset(ts);
	long utcTs = ts + offset;

	switch (startUnit) {
		case MILLENNIUM:
		case CENTURY:
		case YEAR:
		case QUARTER:
		case MONTH:
		case DAY:
		case DOW:
		case DOY:
		case WEEK:
			if (type instanceof TimestampType) {
				long d = divide(utcTs, TimeUnit.DAY.multiplier);
				return DateTimeUtils.unixDateExtract(range, d);
			} else if (type instanceof DateType) {
				return divide(utcTs, TimeUnit.DAY.multiplier);
			} else {
				// TODO support it
				throw new TableException(type + " is unsupported now.");
			}
		case DECADE:
			// TODO support it
			throw new TableException("DECADE is unsupported now.");
		case EPOCH:
			// TODO support it
			throw new TableException("EPOCH is unsupported now.");
		default:
			// fall through
	}

	long res = mod(utcTs, getFactory(startUnit));
	res = divide(res, startUnit.multiplier);
	return res;

}
 
Example #2
Source File: PythonTypeUtilsTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogicalTypeToConversionClassConverter() {
	PythonTypeUtils.LogicalTypeToConversionClassConverter converter =
		PythonTypeUtils.LogicalTypeToConversionClassConverter.INSTANCE;
	ArrayType arrayType = new ArrayType(new ArrayType(new DateType()));
	Class<?> conversionClass = converter.visit(arrayType);
	assertEquals(Date[][].class, conversionClass);
}
 
Example #3
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateType() {
	testAll(
		new DateType(),
		"DATE",
		"DATE",
		new Class[]{java.sql.Date.class, java.time.LocalDate.class, int.class},
		new Class[]{java.time.LocalDate.class},
		new LogicalType[]{},
		new DateType(false)
	);
}
 
Example #4
Source File: FlinkTypeToType.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:CyclomaticComplexity")
@Override
public Type atomic(AtomicDataType type) {
  LogicalType inner = type.getLogicalType();
  if (inner instanceof VarCharType ||
      inner instanceof CharType) {
    return Types.StringType.get();
  } else if (inner instanceof BooleanType) {
    return Types.BooleanType.get();
  } else if (inner instanceof IntType ||
      inner instanceof SmallIntType ||
      inner instanceof TinyIntType) {
    return Types.IntegerType.get();
  } else if (inner instanceof BigIntType) {
    return Types.LongType.get();
  } else if (inner instanceof VarBinaryType) {
    return Types.BinaryType.get();
  } else if (inner instanceof BinaryType) {
    BinaryType binaryType = (BinaryType) inner;
    return Types.FixedType.ofLength(binaryType.getLength());
  } else if (inner instanceof FloatType) {
    return Types.FloatType.get();
  } else if (inner instanceof DoubleType) {
    return Types.DoubleType.get();
  } else if (inner instanceof DateType) {
    return Types.DateType.get();
  } else if (inner instanceof TimeType) {
    return Types.TimeType.get();
  } else if (inner instanceof TimestampType) {
    return Types.TimestampType.withoutZone();
  } else if (inner instanceof LocalZonedTimestampType) {
    return Types.TimestampType.withZone();
  } else if (inner instanceof DecimalType) {
    DecimalType decimalType = (DecimalType) inner;
    return Types.DecimalType.of(decimalType.getPrecision(), decimalType.getScale());
  } else {
    throw new UnsupportedOperationException("Not a supported type: " + type.toString());
  }
}
 
Example #5
Source File: ArrayFieldReader.java    From flink with Apache License 2.0 5 votes vote down vote up
private Class<?> getElementClass(LogicalType elementType) {
	DataType dataType = TypeConversions.fromLogicalToDataType(elementType);
	if (elementType instanceof TimestampType) {
		// the default conversion class is java.time.LocalDateTime
		dataType = dataType.bridgedTo(Timestamp.class);
	} else if (elementType instanceof DateType) {
		// the default conversion class is java.time.LocalDate
		dataType = dataType.bridgedTo(Date.class);
	} else if (elementType instanceof TimeType) {
		// the default conversion class is java.time.LocalTime
		dataType = dataType.bridgedTo(Time.class);
	}
	return dataType.getConversionClass();
}
 
Example #6
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FlinkFnApi.Schema.FieldType visit(DateType dateType) {
	return FlinkFnApi.Schema.FieldType.newBuilder()
		.setTypeName(FlinkFnApi.Schema.TypeName.DATE)
		.setNullable(dateType.isNullable())
		.build();
}
 
Example #7
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateType() {
	testAll(
		new DateType(),
		"DATE",
		"DATE",
		new Class[]{java.sql.Date.class, java.time.LocalDate.class, int.class},
		new Class[]{java.time.LocalDate.class},
		new LogicalType[]{},
		new DateType(false)
	);
}
 
Example #8
Source File: RowDataArrowReaderWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	fieldTypes.add(new TinyIntType());
	fieldTypes.add(new SmallIntType());
	fieldTypes.add(new IntType());
	fieldTypes.add(new BigIntType());
	fieldTypes.add(new BooleanType());
	fieldTypes.add(new FloatType());
	fieldTypes.add(new DoubleType());
	fieldTypes.add(new VarCharType());
	fieldTypes.add(new VarBinaryType());
	fieldTypes.add(new DecimalType(10, 3));
	fieldTypes.add(new DateType());
	fieldTypes.add(new TimeType(0));
	fieldTypes.add(new TimeType(2));
	fieldTypes.add(new TimeType(4));
	fieldTypes.add(new TimeType(8));
	fieldTypes.add(new LocalZonedTimestampType(0));
	fieldTypes.add(new LocalZonedTimestampType(2));
	fieldTypes.add(new LocalZonedTimestampType(4));
	fieldTypes.add(new LocalZonedTimestampType(8));
	fieldTypes.add(new TimestampType(0));
	fieldTypes.add(new TimestampType(2));
	fieldTypes.add(new TimestampType(4));
	fieldTypes.add(new TimestampType(8));
	fieldTypes.add(new ArrayType(new VarCharType()));
	rowFieldType = new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType(Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType()))))));
	fieldTypes.add(rowFieldType);

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (int i = 0; i < fieldTypes.size(); i++) {
		rowFields.add(new RowType.RowField("f" + i, fieldTypes.get(i)));
	}
	rowType = new RowType(rowFields);
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #9
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(DateType dateType) {
	return TypeInfoFactory.dateTypeInfo;
}
 
Example #10
Source File: RowArrowReaderWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	List<LogicalType> fieldTypes = new ArrayList<>();
	fieldTypes.add(new TinyIntType());
	fieldTypes.add(new SmallIntType());
	fieldTypes.add(new IntType());
	fieldTypes.add(new BigIntType());
	fieldTypes.add(new BooleanType());
	fieldTypes.add(new FloatType());
	fieldTypes.add(new DoubleType());
	fieldTypes.add(new VarCharType());
	fieldTypes.add(new VarBinaryType());
	fieldTypes.add(new DecimalType(10, 0));
	fieldTypes.add(new DateType());
	fieldTypes.add(new TimeType(0));
	fieldTypes.add(new TimeType(2));
	fieldTypes.add(new TimeType(4));
	fieldTypes.add(new TimeType(8));
	fieldTypes.add(new LocalZonedTimestampType(0));
	fieldTypes.add(new LocalZonedTimestampType(2));
	fieldTypes.add(new LocalZonedTimestampType(4));
	fieldTypes.add(new LocalZonedTimestampType(8));
	fieldTypes.add(new TimestampType(0));
	fieldTypes.add(new TimestampType(2));
	fieldTypes.add(new TimestampType(4));
	fieldTypes.add(new TimestampType(8));
	fieldTypes.add(new ArrayType(new VarCharType()));
	fieldTypes.add(new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType(Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType())))))));

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (int i = 0; i < fieldTypes.size(); i++) {
		rowFields.add(new RowType.RowField("f" + i, fieldTypes.get(i)));
	}
	rowType = new RowType(rowFields);
	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #11
Source File: ArrowUtilsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init() {
	testFields = new ArrayList<>();
	testFields.add(Tuple7.of(
		"f1", new TinyIntType(), new ArrowType.Int(8, true), RowTinyIntWriter.class,
		TinyIntWriter.TinyIntWriterForRow.class, TinyIntFieldReader.class, ArrowTinyIntColumnVector.class));

	testFields.add(Tuple7.of("f2", new SmallIntType(), new ArrowType.Int(8 * 2, true),
		RowSmallIntWriter.class, SmallIntWriter.SmallIntWriterForRow.class, SmallIntFieldReader.class, ArrowSmallIntColumnVector.class));

	testFields.add(Tuple7.of("f3", new IntType(), new ArrowType.Int(8 * 4, true),
		RowIntWriter.class, IntWriter.IntWriterForRow.class, IntFieldReader.class, ArrowIntColumnVector.class));

	testFields.add(Tuple7.of("f4", new BigIntType(), new ArrowType.Int(8 * 8, true),
		RowBigIntWriter.class, BigIntWriter.BigIntWriterForRow.class, BigIntFieldReader.class, ArrowBigIntColumnVector.class));

	testFields.add(Tuple7.of("f5", new BooleanType(), new ArrowType.Bool(),
		RowBooleanWriter.class, BooleanWriter.BooleanWriterForRow.class, BooleanFieldReader.class, ArrowBooleanColumnVector.class));

	testFields.add(Tuple7.of("f6", new FloatType(), new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE),
		RowFloatWriter.class, FloatWriter.FloatWriterForRow.class, FloatFieldReader.class, ArrowFloatColumnVector.class));

	testFields.add(Tuple7.of("f7", new DoubleType(), new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE),
		RowDoubleWriter.class, DoubleWriter.DoubleWriterForRow.class, DoubleFieldReader.class, ArrowDoubleColumnVector.class));

	testFields.add(Tuple7.of("f8", new VarCharType(), ArrowType.Utf8.INSTANCE,
		RowVarCharWriter.class, VarCharWriter.VarCharWriterForRow.class, VarCharFieldReader.class, ArrowVarCharColumnVector.class));

	testFields.add(Tuple7.of("f9", new VarBinaryType(), ArrowType.Binary.INSTANCE,
		RowVarBinaryWriter.class, VarBinaryWriter.VarBinaryWriterForRow.class, VarBinaryFieldReader.class, ArrowVarBinaryColumnVector.class));

	testFields.add(Tuple7.of("f10", new DecimalType(10, 3), new ArrowType.Decimal(10, 3),
		RowDecimalWriter.class, DecimalWriter.DecimalWriterForRow.class, DecimalFieldReader.class, ArrowDecimalColumnVector.class));

	testFields.add(Tuple7.of("f11", new DateType(), new ArrowType.Date(DateUnit.DAY),
		RowDateWriter.class, DateWriter.DateWriterForRow.class, DateFieldReader.class, ArrowDateColumnVector.class));

	testFields.add(Tuple7.of("f13", new TimeType(0), new ArrowType.Time(TimeUnit.SECOND, 32),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f14", new TimeType(2), new ArrowType.Time(TimeUnit.MILLISECOND, 32),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f15", new TimeType(4), new ArrowType.Time(TimeUnit.MICROSECOND, 64),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f16", new TimeType(8), new ArrowType.Time(TimeUnit.NANOSECOND, 64),
		RowTimeWriter.class, TimeWriter.TimeWriterForRow.class, TimeFieldReader.class, ArrowTimeColumnVector.class));

	testFields.add(Tuple7.of("f17", new LocalZonedTimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f18", new LocalZonedTimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f19", new LocalZonedTimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f20", new LocalZonedTimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f21", new TimestampType(0), new ArrowType.Timestamp(TimeUnit.SECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f22", new TimestampType(2), new ArrowType.Timestamp(TimeUnit.MILLISECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f23", new TimestampType(4), new ArrowType.Timestamp(TimeUnit.MICROSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f24", new TimestampType(8), new ArrowType.Timestamp(TimeUnit.NANOSECOND, null),
		RowTimestampWriter.class, TimestampWriter.TimestampWriterForRow.class, TimestampFieldReader.class, ArrowTimestampColumnVector.class));

	testFields.add(Tuple7.of("f25", new ArrayType(new VarCharType()), ArrowType.List.INSTANCE,
		RowArrayWriter.class, ArrayWriter.ArrayWriterForRow.class, ArrayFieldReader.class, ArrowArrayColumnVector.class));

	RowType rowFieldType = new RowType(Arrays.asList(
		new RowType.RowField("a", new IntType()),
		new RowType.RowField("b", new VarCharType()),
		new RowType.RowField("c", new ArrayType(new VarCharType())),
		new RowType.RowField("d", new TimestampType(2)),
		new RowType.RowField("e", new RowType((Arrays.asList(
			new RowType.RowField("e1", new IntType()),
			new RowType.RowField("e2", new VarCharType())))))));
	testFields.add(Tuple7.of("f26", rowFieldType, ArrowType.Struct.INSTANCE,
		RowRowWriter.class, RowWriter.RowWriterForRow.class, RowFieldReader.class, ArrowRowColumnVector.class));

	List<RowType.RowField> rowFields = new ArrayList<>();
	for (Tuple7<String, LogicalType, ArrowType, Class<?>, Class<?>, Class<?>, Class<?>> field : testFields) {
		rowFields.add(new RowType.RowField(field.f0, field.f1));
	}
	rowType = new RowType(rowFields);

	allocator = ArrowUtils.getRootAllocator().newChildAllocator("stdout", 0, Long.MAX_VALUE);
}
 
Example #12
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ArrowType visit(DateType dateType) {
	return new ArrowType.Date(DateUnit.DAY);
}
 
Example #13
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer visit(DateType dateType) {
	return IntSerializer.INSTANCE;
}
 
Example #14
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer visit(DateType dateType) {
	return DateSerializer.INSTANCE;
}
 
Example #15
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Class visit(DateType dateType) {
	return Date.class;
}
 
Example #16
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(DateType dateType) {
	return defaultMethod(dateType);
}
 
Example #17
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 4 votes vote down vote up
private LogicalType parseTypeByKeyword() {
	nextToken(TokenType.KEYWORD);
	switch (tokenAsKeyword()) {
		case CHAR:
			return parseCharType();
		case VARCHAR:
			return parseVarCharType();
		case STRING:
			return new VarCharType(VarCharType.MAX_LENGTH);
		case BOOLEAN:
			return new BooleanType();
		case BINARY:
			return parseBinaryType();
		case VARBINARY:
			return parseVarBinaryType();
		case BYTES:
			return new VarBinaryType(VarBinaryType.MAX_LENGTH);
		case DECIMAL:
		case NUMERIC:
		case DEC:
			return parseDecimalType();
		case TINYINT:
			return new TinyIntType();
		case SMALLINT:
			return new SmallIntType();
		case INT:
		case INTEGER:
			return new IntType();
		case BIGINT:
			return new BigIntType();
		case FLOAT:
			return new FloatType();
		case DOUBLE:
			return parseDoubleType();
		case DATE:
			return new DateType();
		case TIME:
			return parseTimeType();
		case TIMESTAMP:
			return parseTimestampType();
		case INTERVAL:
			return parseIntervalType();
		case ARRAY:
			return parseArrayType();
		case MULTISET:
			return parseMultisetType();
		case MAP:
			return parseMapType();
		case ROW:
			return parseRowType();
		case NULL:
			return new NullType();
		case RAW:
			return parseRawType();
		case LEGACY:
			return parseLegacyType();
		default:
			throw parsingError("Unsupported type: " + token().value);
	}
}
 
Example #18
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(DateType dateType) {
	return new AtomicDataType(dateType);
}
 
Example #19
Source File: DataTypePrecisionFixerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Parameterized.Parameters(name = "{index}: [From: {0}, To: {1}]")
public static List<TestSpec> testData() {
	return Arrays.asList(

		TestSpecs
			.fix(Types.BIG_DEC)
			.logicalType(new DecimalType(10, 5))
			.expect(DataTypes.DECIMAL(10, 5)),

		TestSpecs
			.fix(Types.SQL_TIMESTAMP)
			.logicalType(new TimestampType(9))
			.expect(DataTypes.TIMESTAMP(9).bridgedTo(Timestamp.class)),

		TestSpecs
			.fix(Types.SQL_TIME)
			.logicalType(new TimeType(9))
			.expect(DataTypes.TIME(9).bridgedTo(Time.class)),

		TestSpecs
			.fix(Types.SQL_DATE)
			.logicalType(new DateType())
			.expect(DataTypes.DATE().bridgedTo(Date.class)),

		TestSpecs
			.fix(Types.LOCAL_DATE_TIME)
			.logicalType(new TimestampType(9))
			.expect(DataTypes.TIMESTAMP(9)),

		TestSpecs
			.fix(Types.LOCAL_TIME)
			.logicalType(new TimeType(9))
			.expect(DataTypes.TIME(9)),

		TestSpecs
			.fix(Types.LOCAL_DATE)
			.logicalType(new DateType())
			.expect(DataTypes.DATE()),

		TestSpecs
			.fix(Types.INSTANT)
			.logicalType(new LocalZonedTimestampType(2))
			.expect(DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(2)),

		TestSpecs
			.fix(Types.STRING)
			.logicalType(new VarCharType(VarCharType.MAX_LENGTH))
			.expect(DataTypes.STRING()),

		// nested
		TestSpecs
			.fix(Types.ROW_NAMED(
				new String[] {"field1", "field2"},
				Types.MAP(Types.BIG_DEC, Types.SQL_TIMESTAMP),
				Types.OBJECT_ARRAY(Types.SQL_TIME)))
			.logicalType(new RowType(
				Arrays.asList(
					new RowType.RowField("field1", new MapType(
						new DecimalType(20, 2),
						new TimestampType(0))),
					new RowType.RowField("field2", new ArrayType(new TimeType(8)))
				)
			))
			.expect(
				DataTypes.ROW(
					FIELD("field1", DataTypes.MAP(
						DataTypes.DECIMAL(20, 2),
						DataTypes.TIMESTAMP(0).bridgedTo(Timestamp.class))),
					FIELD("field2", DataTypes.ARRAY(
						DataTypes.TIME(8).bridgedTo(Time.class)))))

		);
}
 
Example #20
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(DateType dateType) {
	return TypeInfoFactory.dateTypeInfo;
}
 
Example #21
Source File: DataTypesTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Parameters(name = "{index}: {0}=[Logical: {1}, Class: {2}]")
public static List<Object[]> dataTypes() {
	return Arrays.asList(
		new Object[][]{
			{CHAR(2), new CharType(2), String.class},

			{VARCHAR(2), new VarCharType(2), String.class},

			{STRING(), new VarCharType(VarCharType.MAX_LENGTH), String.class},

			{BOOLEAN(), new BooleanType(), Boolean.class},

			{BINARY(42), new BinaryType(42), byte[].class},

			{VARBINARY(42), new VarBinaryType(42), byte[].class},

			{BYTES(), new VarBinaryType(VarBinaryType.MAX_LENGTH), byte[].class},

			{DECIMAL(10, 10), new DecimalType(10, 10), BigDecimal.class},

			{TINYINT(), new TinyIntType(), Byte.class},

			{SMALLINT(), new SmallIntType(), Short.class},

			{INT(), new IntType(), Integer.class},

			{BIGINT(), new BigIntType(), Long.class},

			{FLOAT(), new FloatType(), Float.class},

			{DOUBLE(), new DoubleType(), Double.class},

			{DATE(), new DateType(), java.time.LocalDate.class},

			{TIME(3), new TimeType(3), java.time.LocalTime.class},

			{TIME(), new TimeType(0), java.time.LocalTime.class},

			{TIMESTAMP(3), new TimestampType(3), java.time.LocalDateTime.class},

			{TIMESTAMP(), new TimestampType(6), java.time.LocalDateTime.class},

			{TIMESTAMP_WITH_TIME_ZONE(3),
				new ZonedTimestampType(3),
				java.time.OffsetDateTime.class},

			{TIMESTAMP_WITH_TIME_ZONE(),
				new ZonedTimestampType(6),
				java.time.OffsetDateTime.class},

			{TIMESTAMP_WITH_LOCAL_TIME_ZONE(3),
				new LocalZonedTimestampType(3),
				java.time.Instant.class},

			{TIMESTAMP_WITH_LOCAL_TIME_ZONE(),
				new LocalZonedTimestampType(6),
				java.time.Instant.class},

			{INTERVAL(MINUTE(), SECOND(3)),
				new DayTimeIntervalType(MINUTE_TO_SECOND, DEFAULT_DAY_PRECISION, 3),
				java.time.Duration.class},

			{INTERVAL(MONTH()),
				new YearMonthIntervalType(YearMonthResolution.MONTH),
				java.time.Period.class},

			{ARRAY(ARRAY(INT())),
				new ArrayType(new ArrayType(new IntType())),
				Integer[][].class},

			{MULTISET(MULTISET(INT())),
				new MultisetType(new MultisetType(new IntType())),
				Map.class},

			{MAP(INT(), SMALLINT()),
				new MapType(new IntType(), new SmallIntType()),
				Map.class},

			{ROW(FIELD("field1", CHAR(2)), FIELD("field2", BOOLEAN())),
				new RowType(
					Arrays.asList(
						new RowType.RowField("field1", new CharType(2)),
						new RowType.RowField("field2", new BooleanType()))),
				Row.class},

			{NULL(), new NullType(), Object.class},

			{ANY(Types.GENERIC(DataTypesTest.class)),
				new TypeInformationAnyType<>(Types.GENERIC(DataTypesTest.class)),
				DataTypesTest.class},

			{ANY(Void.class, VoidSerializer.INSTANCE),
				new AnyType<>(Void.class, VoidSerializer.INSTANCE),
				Void.class}
		}
	);
}
 
Example #22
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(DateType dateType) {
	return defaultMethod(dateType);
}
 
Example #23
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 4 votes vote down vote up
private LogicalType parseTypeByKeyword() {
	nextToken(TokenType.KEYWORD);
	switch (tokenAsKeyword()) {
		case CHAR:
			return parseCharType();
		case VARCHAR:
			return parseVarCharType();
		case STRING:
			return new VarCharType(VarCharType.MAX_LENGTH);
		case BOOLEAN:
			return new BooleanType();
		case BINARY:
			return parseBinaryType();
		case VARBINARY:
			return parseVarBinaryType();
		case BYTES:
			return new VarBinaryType(VarBinaryType.MAX_LENGTH);
		case DECIMAL:
		case NUMERIC:
		case DEC:
			return parseDecimalType();
		case TINYINT:
			return new TinyIntType();
		case SMALLINT:
			return new SmallIntType();
		case INT:
		case INTEGER:
			return new IntType();
		case BIGINT:
			return new BigIntType();
		case FLOAT:
			return new FloatType();
		case DOUBLE:
			return parseDoubleType();
		case DATE:
			return new DateType();
		case TIME:
			return parseTimeType();
		case TIMESTAMP:
			return parseTimestampType();
		case INTERVAL:
			return parseIntervalType();
		case ARRAY:
			return parseArrayType();
		case MULTISET:
			return parseMultisetType();
		case MAP:
			return parseMapType();
		case ROW:
			return parseRowType();
		case NULL:
			return new NullType();
		case ANY:
			return parseAnyType();
		default:
			throw parsingError("Unsupported type: " + token().value);
	}
}
 
Example #24
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(DateType dateType) {
	return new AtomicDataType(dateType);
}
 
Example #25
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of a date consisting of {@code year-month-day} with values ranging from {@code 0000-01-01}
 * to {@code 9999-12-31}.
 *
 * <p>Compared to the SQL standard, the range starts at year {@code 0000}.
 *
 * @see DataType
 */
public static DataType DATE() {
	return new AtomicDataType(new DateType());
}
 
Example #26
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of a date consisting of {@code year-month-day} with values ranging from {@code 0000-01-01}
 * to {@code 9999-12-31}.
 *
 * <p>Compared to the SQL standard, the range starts at year {@code 0000}.
 *
 * @see DataType
 */
public static DataType DATE() {
	return new AtomicDataType(new DateType());
}