Java Code Examples for org.apache.flink.table.types.logical.TinyIntType#PRECISION

The following examples show how to use org.apache.flink.table.types.logical.TinyIntType#PRECISION . 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: 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 2
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 3
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;
}