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

The following examples show how to use org.apache.flink.table.types.logical.DoubleType. 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: BytesHashMapTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public BytesHashMapTest() {

		this.keyTypes = new LogicalType[] {
				new IntType(),
				new VarCharType(VarCharType.MAX_LENGTH),
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};
		this.valueTypes = new LogicalType[] {
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};

		this.keySerializer = new BinaryRowSerializer(keyTypes.length);
		this.valueSerializer = new BinaryRowSerializer(valueTypes.length);
		this.defaultValue = valueSerializer.createInstance();
		int valueSize = defaultValue.getFixedLengthPartSize();
		this.defaultValue.pointTo(MemorySegmentFactory.wrap(new byte[valueSize]), 0, valueSize);
	}
 
Example #2
Source File: BytesHashMapTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public BytesHashMapTest() {

		this.keyTypes = new LogicalType[] {
				new IntType(),
				new VarCharType(VarCharType.MAX_LENGTH),
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};
		this.valueTypes = new LogicalType[] {
				new DoubleType(),
				new BigIntType(),
				new BooleanType(),
				new FloatType(),
				new SmallIntType()
		};

		this.keySerializer = new BinaryRowDataSerializer(keyTypes.length);
		this.valueSerializer = new BinaryRowDataSerializer(valueTypes.length);
		this.defaultValue = valueSerializer.createInstance();
		int valueSize = defaultValue.getFixedLengthPartSize();
		this.defaultValue.pointTo(MemorySegmentFactory.wrap(new byte[valueSize]), 0, valueSize);
	}
 
Example #3
Source File: BaseRowSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testBaseRowSerializerWithComplexTypes() {
	BaseRowTypeInfo typeInfo = new BaseRowTypeInfo(
		new IntType(),
		new DoubleType(),
		new VarCharType(VarCharType.MAX_LENGTH),
		new ArrayType(new IntType()),
		new MapType(new IntType(), new IntType()));

	GenericRow[] data = new GenericRow[]{
		createRow(null, null, null, null, null),
		createRow(0, null, null, null, null),
		createRow(0, 0.0, null, null, null),
		createRow(0, 0.0, fromString("a"), null, null),
		createRow(1, 0.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("b"), null, null),
		createRow(1, 1.0, fromString("b"), createArray(1), createMap(new int[]{1}, new int[]{1})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2), createMap(new int[]{1, 4}, new int[]{1, 2})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3), createMap(new int[]{1, 5}, new int[]{1, 3})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4), createMap(new int[]{1, 6}, new int[]{1, 4})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5), createMap(new int[]{1, 7}, new int[]{1, 5})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5, 6), createMap(new int[]{1, 8}, new int[]{1, 6}))
	};

	BaseRowSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, data};
}
 
Example #4
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FlinkFnApi.Schema.FieldType visit(DoubleType doubleType) {
	return FlinkFnApi.Schema.FieldType.newBuilder()
		.setTypeName(FlinkFnApi.Schema.TypeName.DOUBLE)
		.setNullable(doubleType.isNullable())
		.build();
}
 
Example #5
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoubleType() {
	testAll(
		new DoubleType(),
		"DOUBLE",
		"DOUBLE",
		new Class[]{Double.class, double.class},
		new Class[]{Double.class},
		new LogicalType[]{},
		new DoubleType(false)
	);
}
 
Example #6
Source File: RowDataSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Object[] testRowDataSerializerWithComplexTypes() {
	RowDataTypeInfo typeInfo = new RowDataTypeInfo(
		new IntType(),
		new DoubleType(),
		new VarCharType(VarCharType.MAX_LENGTH),
		new ArrayType(new IntType()),
		new MapType(new IntType(), new IntType()));

	GenericRowData[] data = new GenericRowData[]{
		createRow(null, null, null, null, null),
		createRow(0, null, null, null, null),
		createRow(0, 0.0, null, null, null),
		createRow(0, 0.0, fromString("a"), null, null),
		createRow(1, 0.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("a"), null, null),
		createRow(1, 1.0, fromString("b"), null, null),
		createRow(1, 1.0, fromString("b"), createArray(1), createMap(new int[]{1}, new int[]{1})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2), createMap(new int[]{1, 4}, new int[]{1, 2})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3), createMap(new int[]{1, 5}, new int[]{1, 3})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4), createMap(new int[]{1, 6}, new int[]{1, 4})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5), createMap(new int[]{1, 7}, new int[]{1, 5})),
		createRow(1, 1.0, fromString("b"), createArray(1, 2, 3, 4, 5, 6), createMap(new int[]{1, 8}, new int[]{1, 6}))
	};

	RowDataSerializer serializer = typeInfo.createSerializer(new ExecutionConfig());
	return new Object[] {serializer, data};
}
 
Example #7
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 #8
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoubleType() {
	testAll(
		new DoubleType(),
		"DOUBLE",
		"DOUBLE",
		new Class[]{Double.class, double.class},
		new Class[]{Double.class},
		new LogicalType[]{},
		new DoubleType(false)
	);
}
 
Example #9
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 4 votes vote down vote up
private LogicalType parseDoubleType() {
	if (hasNextToken(Keyword.PRECISION)) {
		nextToken(Keyword.PRECISION);
	}
	return new DoubleType();
}
 
Example #10
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 #11
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 #12
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 #13
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ArrowType visit(DoubleType doubleType) {
	return new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE);
}
 
Example #14
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(DoubleType doubleType) {
	return TypeInfoFactory.doubleTypeInfo;
}
 
Example #15
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer visit(DoubleType doubleType) {
	return DoubleSerializer.INSTANCE;
}
 
Example #16
Source File: ParquetColumnarRowSplitReaderTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private int readSplitAndCheck(
		int start,
		long seekToRow,
		Path testPath,
		long splitStart,
		long splitLength,
		List<Integer> values) throws IOException {
	LogicalType[] fieldTypes = new LogicalType[]{
			new VarCharType(VarCharType.MAX_LENGTH),
			new BooleanType(),
			new TinyIntType(),
			new SmallIntType(),
			new IntType(),
			new BigIntType(),
			new FloatType(),
			new DoubleType(),
			new TimestampType(9),
			new DecimalType(5, 0),
			new DecimalType(15, 0),
			new DecimalType(20, 0),
			new DecimalType(5, 0),
			new DecimalType(15, 0),
			new DecimalType(20, 0)};

	ParquetColumnarRowSplitReader reader = new ParquetColumnarRowSplitReader(
			false,
			true,
			new Configuration(),
			fieldTypes,
			new String[] {
					"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
					"f8", "f9", "f10", "f11", "f12", "f13", "f14"},
			VectorizedColumnBatch::new,
			500,
			new org.apache.hadoop.fs.Path(testPath.getPath()),
			splitStart,
			splitLength);
	reader.seekToRow(seekToRow);

	int i = start;
	while (!reader.reachedEnd()) {
		ColumnarRowData row = reader.nextRecord();
		Integer v = values.get(i);
		if (v == null) {
			assertTrue(row.isNullAt(0));
			assertTrue(row.isNullAt(1));
			assertTrue(row.isNullAt(2));
			assertTrue(row.isNullAt(3));
			assertTrue(row.isNullAt(4));
			assertTrue(row.isNullAt(5));
			assertTrue(row.isNullAt(6));
			assertTrue(row.isNullAt(7));
			assertTrue(row.isNullAt(8));
			assertTrue(row.isNullAt(9));
			assertTrue(row.isNullAt(10));
			assertTrue(row.isNullAt(11));
			assertTrue(row.isNullAt(12));
			assertTrue(row.isNullAt(13));
			assertTrue(row.isNullAt(14));
		} else {
			assertEquals("" + v, row.getString(0).toString());
			assertEquals(v % 2 == 0, row.getBoolean(1));
			assertEquals(v.byteValue(), row.getByte(2));
			assertEquals(v.shortValue(), row.getShort(3));
			assertEquals(v.intValue(), row.getInt(4));
			assertEquals(v.longValue(), row.getLong(5));
			assertEquals(v.floatValue(), row.getFloat(6), 0);
			assertEquals(v.doubleValue(), row.getDouble(7), 0);
			assertEquals(
					toDateTime(v),
					row.getTimestamp(8, 9).toLocalDateTime());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(9, 5, 0).toBigDecimal());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(10, 15, 0).toBigDecimal());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(11, 20, 0).toBigDecimal());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(12, 5, 0).toBigDecimal());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(13, 15, 0).toBigDecimal());
			assertEquals(BigDecimal.valueOf(v), row.getDecimal(14, 20, 0).toBigDecimal());
		}
		i++;
	}
	reader.close();
	return i - start;
}
 
Example #17
Source File: LogicalTypeMerging.java    From flink with Apache License 2.0 4 votes vote down vote up
private static LogicalType createCommonApproximateNumericType(LogicalType resultType, LogicalType type) {
	if (hasRoot(resultType, DOUBLE) || hasRoot(type, DOUBLE)) {
		return new DoubleType();
	}
	return resultType;
}
 
Example #18
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(DoubleType doubleType) {
	return defaultMethod(doubleType);
}
 
Example #19
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 #20
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(DoubleType doubleType) {
	return DoubleType.PRECISION;
}
 
Example #21
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(DoubleType doubleType) {
	return new AtomicDataType(doubleType);
}
 
Example #22
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(DoubleType doubleType) {
	return new AtomicDataType(doubleType);
}
 
Example #23
Source File: LogicalTypeParser.java    From flink with Apache License 2.0 4 votes vote down vote up
private LogicalType parseDoubleType() {
	if (hasNextToken(Keyword.PRECISION)) {
		nextToken(Keyword.PRECISION);
	}
	return new DoubleType();
}
 
Example #24
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(DoubleType doubleType) {
	return TypeInfoFactory.doubleTypeInfo;
}
 
Example #25
Source File: KuduTypeUtils.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public Type visit(DoubleType doubleType) {
    return Type.DOUBLE;
}
 
Example #26
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(DoubleType doubleType) {
	return defaultMethod(doubleType);
}
 
Example #27
Source File: LogicalTypeGeneralization.java    From flink with Apache License 2.0 4 votes vote down vote up
private static LogicalType createCommonApproximateNumericType(LogicalType resultType, LogicalType type) {
	if (hasRoot(resultType, DOUBLE) || hasRoot(type, DOUBLE)) {
		return new DoubleType();
	}
	return resultType;
}
 
Example #28
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of an 8-byte double precision floating point number.
 *
 * @see DoubleType
 */
public static DataType DOUBLE() {
	return new AtomicDataType(new DoubleType());
}
 
Example #29
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of an 8-byte double precision floating point number.
 *
 * @see DoubleType
 */
public static DataType DOUBLE() {
	return new AtomicDataType(new DoubleType());
}