Java Code Examples for org.apache.flink.table.api.DataTypes#BIGINT

The following examples show how to use org.apache.flink.table.api.DataTypes#BIGINT . 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: HiveGenericUDAFTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUDAFMin() throws Exception {
	Object[] constantArgs = new Object[] {
		null
	};

	DataType[] argTypes = new DataType[] {
		DataTypes.BIGINT()
	};

	HiveGenericUDAF udf = init(GenericUDAFMin.class, constantArgs, argTypes);

	GenericUDAFEvaluator.AggregationBuffer acc = udf.createAccumulator();

	udf.accumulate(acc, 2L);
	udf.accumulate(acc, 3L);
	udf.accumulate(acc, 1L);

	udf.merge(acc, Arrays.asList());

	assertEquals(1L, udf.getValue(acc));
}
 
Example 2
Source File: HiveCatalogDataTypeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataTypes() throws Exception {
	DataType[] types = new DataType[] {
		DataTypes.TINYINT(),
		DataTypes.SMALLINT(),
		DataTypes.INT(),
		DataTypes.BIGINT(),
		DataTypes.FLOAT(),
		DataTypes.DOUBLE(),
		DataTypes.BOOLEAN(),
		DataTypes.STRING(),
		DataTypes.BYTES(),
		DataTypes.DATE(),
		DataTypes.TIMESTAMP(),
		DataTypes.CHAR(HiveChar.MAX_CHAR_LENGTH),
		DataTypes.VARCHAR(HiveVarchar.MAX_VARCHAR_LENGTH),
		DataTypes.DECIMAL(5, 3)
	};

	verifyDataTypes(types);
}
 
Example 3
Source File: TypeMappingUtilsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongLogicalTypeForRowtimeAttribute() {
	thrown.expect(ValidationException.class);
	thrown.expectMessage(
		"Rowtime field 'rowtime' has invalid type TIME(0). Rowtime attributes must be of a Timestamp family.");

	TestTableSource tableSource = new TestTableSource(
		DataTypes.BIGINT(),
		Collections.singletonList("rowtime"),
		"proctime"
	);
	TypeMappingUtils.computePhysicalIndicesOrTimeAttributeMarkers(
		tableSource,
		TableSchema.builder()
			.field("a", Types.LONG)
			.field("rowtime", Types.SQL_TIME)
			.field("proctime", Types.SQL_TIMESTAMP)
			.build().getTableColumns(),
		false,
		Function.identity()
	);
}
 
Example 4
Source File: TypeMappingUtilsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongLogicalTypeForProctimeAttribute() {
	thrown.expect(ValidationException.class);
	thrown.expectMessage(
		"Proctime field 'proctime' has invalid type TIME(0). Proctime attributes must be of a Timestamp family.");

	TestTableSource tableSource = new TestTableSource(
		DataTypes.BIGINT(),
		Collections.singletonList("rowtime"),
		"proctime"
	);
	TypeMappingUtils.computePhysicalIndicesOrTimeAttributeMarkers(
		tableSource,
		TableSchema.builder()
			.field("a", Types.LONG)
			.field("rowtime", Types.SQL_TIMESTAMP)
			.field("proctime", Types.SQL_TIME)
			.build().getTableColumns(),
		false,
		Function.identity()
	);
}
 
Example 5
Source File: SumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType[] getAggBufferTypes() {
	return new DataType[] {
			getResultType(),
			DataTypes.BIGINT() };
}
 
Example 6
Source File: LeadLagAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 7
Source File: IndexGeneratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void prepareData() {
	String[] fieldNames = new String[]{
		"id",
		"item",
		"log_ts",
		"log_date",
		"order_timestamp",
		"log_time",
		"local_datetime",
		"local_date",
		"local_time",
		"note",
		"status"};
	DataType[] dataTypes = new DataType[]{
		DataTypes.INT(),
		DataTypes.STRING(),
		DataTypes.BIGINT(),
		DataTypes.DATE().bridgedTo(java.sql.Date.class),
		DataTypes.TIMESTAMP().bridgedTo(java.sql.Timestamp.class),
		DataTypes.TIME().bridgedTo(java.sql.Time.class),
		DataTypes.TIMESTAMP().bridgedTo(java.time.LocalDateTime.class),
		DataTypes.DATE().bridgedTo(java.time.LocalDate.class),
		DataTypes.TIME().bridgedTo(java.time.LocalTime.class),
		DataTypes.STRING(),
		DataTypes.BOOLEAN()
	};
	schema = new TableSchema.Builder().fields(fieldNames, dataTypes).build();

	rows = new ArrayList<>();
	rows.add(Row.of(
		1,
		"apple",
		Timestamp.valueOf("2020-03-18 12:12:14").getTime(),
		Date.valueOf("2020-03-18"),
		Timestamp.valueOf("2020-03-18 12:12:14"),
		Time.valueOf("12:12:14"),
		LocalDateTime.of(2020, 3, 18, 12, 12, 14, 1000),
		LocalDate.of(2020, 3, 18),
		LocalTime.of(12, 13, 14, 2000),
		"test1",
		true));
	rows.add(Row.of(
		2,
		"peanut",
		Timestamp.valueOf("2020-03-19 12:22:14").getTime(),
		Date.valueOf("2020-03-19"),
		Timestamp.valueOf("2020-03-19 12:22:21"),
		Time.valueOf("12:22:21"),
		LocalDateTime.of(2020, 3, 19, 12, 22, 14, 1000),
		LocalDate.of(2020, 3, 19),
		LocalTime.of(12, 13, 14, 2000),
		"test2",
		false));
}
 
Example 8
Source File: MaxAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 9
Source File: LeadLagAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 10
Source File: AvgAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getSumType() {
	return DataTypes.BIGINT();
}
 
Example 11
Source File: IncrSumAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 12
Source File: MinAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 13
Source File: Sum0AggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 14
Source File: AvgAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 15
Source File: SingleValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 16
Source File: Count1AggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType getResultType() {
	return DataTypes.BIGINT();
}
 
Example 17
Source File: RowNumberAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType[] getAggBufferTypes() {
	return new DataType[] { DataTypes.BIGINT() };
}
 
Example 18
Source File: SumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType[] getAggBufferTypes() {
	return new DataType[] {
			getResultType(),
			DataTypes.BIGINT() };
}
 
Example 19
Source File: IncrSumWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public DataType[] getAggBufferTypes() {
	return new DataType[] {
			getResultType(),
			DataTypes.BIGINT() };
}
 
Example 20
Source File: SchemaUtils.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
private static DataType avro2SqlType(Schema avroSchema, Set<String> existingRecordNames) throws IncompatibleSchemaException {
    LogicalType logicalType = avroSchema.getLogicalType();
    switch (avroSchema.getType()) {
        case INT:
            if (logicalType instanceof LogicalTypes.Date) {
                return DataTypes.DATE();
            } else {
                return DataTypes.INT();
            }

        case STRING:
        case ENUM:
            return DataTypes.STRING();

        case BOOLEAN:
            return DataTypes.BOOLEAN();

        case BYTES:
        case FIXED:
            // For FIXED type, if the precision requires more bytes than fixed size, the logical
            // type will be null, which is handled by Avro library.
            if (logicalType instanceof LogicalTypes.Decimal) {
                LogicalTypes.Decimal d = (LogicalTypes.Decimal) logicalType;
                return DataTypes.DECIMAL(d.getPrecision(), d.getScale());
            } else {
                return DataTypes.BYTES();
            }

        case DOUBLE:
            return DataTypes.DOUBLE();

        case FLOAT:
            return DataTypes.FLOAT();

        case LONG:
            if (logicalType instanceof LogicalTypes.TimestampMillis ||
                    logicalType instanceof LogicalTypes.TimestampMicros) {
                return DataTypes.TIMESTAMP(3).bridgedTo(java.sql.Timestamp.class);
            } else {
                return DataTypes.BIGINT();
            }

        case RECORD:
            if (existingRecordNames.contains(avroSchema.getFullName())) {
                throw new IncompatibleSchemaException(
                        String.format("Found recursive reference in Avro schema, which can not be processed by Flink: %s", avroSchema.toString(true)), null);
            }

            Set<String> newRecordName = ImmutableSet.<String>builder()
                    .addAll(existingRecordNames).add(avroSchema.getFullName()).build();
            List<DataTypes.Field> fields = new ArrayList<>();
            for (Schema.Field f : avroSchema.getFields()) {
                DataType fieldType = avro2SqlType(f.schema(), newRecordName);
                fields.add(DataTypes.FIELD(f.name(), fieldType));
            }
            return DataTypes.ROW(fields.toArray(new DataTypes.Field[0]));

        case ARRAY:
            DataType elementType = avro2SqlType(avroSchema.getElementType(), existingRecordNames);
            return DataTypes.ARRAY(elementType);

        case MAP:
            DataType valueType = avro2SqlType(avroSchema.getValueType(), existingRecordNames);
            return DataTypes.MAP(DataTypes.STRING(), valueType);

        case UNION:
            if (avroSchema.getTypes().stream().anyMatch(f -> f.getType() == Schema.Type.NULL)) {
                // In case of a union with null, eliminate it and make a recursive call
                List<Schema> remainingUnionTypes =
                        avroSchema.getTypes().stream().filter(f -> f.getType() != Schema.Type.NULL).collect(Collectors.toList());
                if (remainingUnionTypes.size() == 1) {
                    return avro2SqlType(remainingUnionTypes.get(0), existingRecordNames).nullable();
                } else {
                    return avro2SqlType(Schema.createUnion(remainingUnionTypes), existingRecordNames).nullable();
                }
            } else {
                List<Schema.Type> types = avroSchema.getTypes().stream().map(Schema::getType).collect(Collectors.toList());
                if (types.size() == 1) {
                    return avro2SqlType(avroSchema.getTypes().get(0), existingRecordNames);
                } else if (types.size() == 2 && types.contains(Schema.Type.INT) && types.contains(Schema.Type.LONG)) {
                    return DataTypes.BIGINT();
                } else if (types.size() == 2 && types.contains(Schema.Type.FLOAT) && types.contains(Schema.Type.DOUBLE)) {
                    return DataTypes.DOUBLE();
                } else {
                    // Convert complex unions to struct types where field names are member0, member1, etc.
                    // This is consistent with the behavior when converting between Avro and Parquet.
                    List<DataTypes.Field> memberFields = new ArrayList<>();
                    List<Schema> schemas = avroSchema.getTypes();
                    for (int i = 0; i < schemas.size(); i++) {
                        DataType memberType = avro2SqlType(schemas.get(i), existingRecordNames);
                        memberFields.add(DataTypes.FIELD("member" + i, memberType));
                    }
                    return DataTypes.ROW(memberFields.toArray(new DataTypes.Field[0]));
                }
            }

        default:
            throw new IncompatibleSchemaException(String.format("Unsupported type %s", avroSchema.toString(true)), null);
    }
}