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

The following examples show how to use org.apache.flink.table.types.logical.TinyIntType. 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: PythonTypeUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public FlinkFnApi.Schema.FieldType visit(TinyIntType tinyIntType) {
	return FlinkFnApi.Schema.FieldType.newBuilder()
		.setTypeName(FlinkFnApi.Schema.TypeName.TINYINT)
		.setNullable(tinyIntType.isNullable())
		.build();
}
 
Example #2
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTinyIntType() {
	testAll(
		new TinyIntType(),
		"TINYINT",
		"TINYINT",
		new Class[]{Byte.class, byte.class},
		new Class[]{Byte.class},
		new LogicalType[]{},
		new TinyIntType(false)
	);
}
 
Example #3
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 #4
Source File: LogicalTypesTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTinyIntType() {
	testAll(
		new TinyIntType(),
		"TINYINT",
		"TINYINT",
		new Class[]{Byte.class, byte.class},
		new Class[]{Byte.class},
		new LogicalType[]{},
		new TinyIntType(false)
	);
}
 
Example #5
Source File: PrintUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Try to derive column width based on column types.
 * If result set is not small enough to be stored in java heap memory,
 * we can't determine column widths based on column values.
 */
public static int[] columnWidthsByType(
		List<TableColumn> columns,
		int maxColumnWidth,
		String nullColumn,
		@Nullable String rowKindColumn) {
	// fill width with field names first
	final int[] colWidths = columns.stream()
			.mapToInt(col -> col.getName().length())
			.toArray();

	// determine proper column width based on types
	for (int i = 0; i < columns.size(); ++i) {
		LogicalType type = columns.get(i).getType().getLogicalType();
		int len;
		switch (type.getTypeRoot()) {
			case TINYINT:
				len = TinyIntType.PRECISION + 1; // extra for negative value
				break;
			case SMALLINT:
				len = SmallIntType.PRECISION + 1; // extra for negative value
				break;
			case INTEGER:
				len = IntType.PRECISION + 1; // extra for negative value
				break;
			case BIGINT:
				len = BigIntType.PRECISION + 1; // extra for negative value
				break;
			case DECIMAL:
				len = ((DecimalType) type).getPrecision() + 2; // extra for negative value and decimal point
				break;
			case BOOLEAN:
				len = 5; // "true" or "false"
				break;
			case DATE:
				len = 10; // e.g. 9999-12-31
				break;
			case TIME_WITHOUT_TIME_ZONE:
				int precision = ((TimeType) type).getPrecision();
				len = precision == 0 ? 8 : precision + 9; // 23:59:59[.999999999]
				break;
			case TIMESTAMP_WITHOUT_TIME_ZONE:
				precision = ((TimestampType) type).getPrecision();
				len = timestampTypeColumnWidth(precision);
				break;
			case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
				precision = ((LocalZonedTimestampType) type).getPrecision();
				len = timestampTypeColumnWidth(precision);
				break;
			default:
				len = maxColumnWidth;
		}

		// adjust column width with potential null values
		colWidths[i] = Math.max(colWidths[i], Math.max(len, nullColumn.length()));
	}

	// add an extra column for row kind if necessary
	if (rowKindColumn != null) {
		final int[] ret = new int[columns.size() + 1];
		ret[0] = rowKindColumn.length();
		System.arraycopy(colWidths, 0, ret, 1, columns.size());
		return ret;
	} else {
		return colWidths;
	}
}
 
Example #6
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 #7
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 #8
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 #9
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ArrowType visit(TinyIntType tinyIntType) {
	return new ArrowType.Int(8, true);
}
 
Example #10
Source File: PythonTypeUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer visit(TinyIntType tinyIntType) {
	return ByteSerializer.INSTANCE;
}
 
Example #11
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 #12
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(TinyIntType tinyIntType) {
	return defaultMethod(tinyIntType);
}
 
Example #13
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 #14
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(TinyIntType tinyIntType) {
	return 0;
}
 
Example #15
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(TinyIntType tinyIntType) {
	return TinyIntType.PRECISION;
}
 
Example #16
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(TinyIntType tinyIntType) {
	return new AtomicDataType(tinyIntType);
}
 
Example #17
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(TinyIntType tinyIntType) {
	return TypeInfoFactory.byteTypeInfo;
}
 
Example #18
Source File: HiveTypeUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInfo visit(TinyIntType tinyIntType) {
	return TypeInfoFactory.byteTypeInfo;
}
 
Example #19
Source File: KuduTypeUtils.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public Type visit(TinyIntType tinyIntType) {
    return Type.INT8;
}
 
Example #20
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 #21
Source File: LogicalTypeDefaultVisitor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public R visit(TinyIntType tinyIntType) {
	return defaultMethod(tinyIntType);
}
 
Example #22
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 #23
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(TinyIntType tinyIntType) {
	return 0;
}
 
Example #24
Source File: LogicalTypeChecks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Integer visit(TinyIntType tinyIntType) {
	return TinyIntType.PRECISION;
}
 
Example #25
Source File: LogicalTypeDataTypeConverter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType visit(TinyIntType tinyIntType) {
	return new AtomicDataType(tinyIntType);
}
 
Example #26
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of a 1-byte signed integer with values from -128 to 127.
 *
 * @see TinyIntType
 */
public static DataType TINYINT() {
	return new AtomicDataType(new TinyIntType());
}
 
Example #27
Source File: DataTypes.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Data type of a 1-byte signed integer with values from -128 to 127.
 *
 * @see TinyIntType
 */
public static DataType TINYINT() {
	return new AtomicDataType(new TinyIntType());
}