Java Code Examples for org.apache.flink.api.common.typeinfo.BasicTypeInfo#LONG_TYPE_INFO

The following examples show how to use org.apache.flink.api.common.typeinfo.BasicTypeInfo#LONG_TYPE_INFO . These examples are extracted from open source projects. 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
private static <InT, OutT> StreamingLedgerSpec<InT, OutT> createSpecificationUnderTest(
        TransactionProcessFunction<InT, OutT> processFunction,
        TypeInformation<InT> inType,
        TypeInformation<OutT> outType) {

    State<Integer, Long> state = new State<>(
            "state",
            BasicTypeInfo.INT_TYPE_INFO,
            BasicTypeInfo.LONG_TYPE_INFO);

    StateAccessSpec<InT, Integer, Long> accessSpec = new StateAccessSpec<>(
            "value",
            state,
            Object::hashCode,
            AccessType.READ_WRITE);

    List<StateAccessSpec<InT, ?, ?>> bindings = Collections.singletonList(accessSpec);
    return StreamingLedgerSpecFactory.create(processFunction, bindings, inType, outType);
}
 
Example 2
@Override
public void open(Configuration parameters) throws Exception {
	function = genAggsHandler.newInstance(getRuntimeContext().getUserCodeClassLoader());
	function.open(new PerKeyStateDataViewStore(getRuntimeContext()));

	output = new JoinedRowData();

	// input element are all binary row as they are came from network
	RowDataTypeInfo inputType = new RowDataTypeInfo(inputFieldTypes);
	// we keep the elements received in a map state indexed based on their ingestion time
	ListTypeInfo<RowData> rowListTypeInfo = new ListTypeInfo<>(inputType);
	MapStateDescriptor<Long, List<RowData>> mapStateDescriptor = new MapStateDescriptor<>(
		"inputState", BasicTypeInfo.LONG_TYPE_INFO, rowListTypeInfo);
	inputState = getRuntimeContext().getMapState(mapStateDescriptor);

	RowDataTypeInfo accTypeInfo = new RowDataTypeInfo(accTypes);
	ValueStateDescriptor<RowData> stateDescriptor =
		new ValueStateDescriptor<RowData>("accState", accTypeInfo);
	accState = getRuntimeContext().getState(stateDescriptor);

	ValueStateDescriptor<Long> cleanupTsStateDescriptor = new ValueStateDescriptor<>(
		"cleanupTsState",
		Types.LONG
	);
	this.cleanupTsState = getRuntimeContext().getState(cleanupTsStateDescriptor);
}
 
Example 3
Source Project: Flink-CEPplus   File: OrcTableSource.java    License: Apache License 2.0 6 votes vote down vote up
private PredicateLeaf.Type toOrcType(TypeInformation<?> type) {
	if (type == BasicTypeInfo.BYTE_TYPE_INFO ||
		type == BasicTypeInfo.SHORT_TYPE_INFO ||
		type == BasicTypeInfo.INT_TYPE_INFO ||
		type == BasicTypeInfo.LONG_TYPE_INFO) {
		return PredicateLeaf.Type.LONG;
	} else if (type == BasicTypeInfo.FLOAT_TYPE_INFO ||
		type == BasicTypeInfo.DOUBLE_TYPE_INFO) {
		return PredicateLeaf.Type.FLOAT;
	} else if (type == BasicTypeInfo.BOOLEAN_TYPE_INFO) {
		return PredicateLeaf.Type.BOOLEAN;
	} else if (type == BasicTypeInfo.STRING_TYPE_INFO) {
		return PredicateLeaf.Type.STRING;
	} else if (type == SqlTimeTypeInfo.TIMESTAMP) {
		return PredicateLeaf.Type.TIMESTAMP;
	} else if (type == SqlTimeTypeInfo.DATE) {
		return PredicateLeaf.Type.DATE;
	} else if (type == BasicTypeInfo.BIG_DEC_TYPE_INFO) {
		return PredicateLeaf.Type.DECIMAL;
	} else {
		// unsupported type
		return null;
	}
}
 
Example 4
@Test
public void testAreCompatible2() throws Keys.IncompatibleKeysException {
	TypeInformation<PojoWithMultiplePojos> t1 = TypeExtractor.getForClass(PojoWithMultiplePojos.class);
	TypeInformation<Tuple3<Long, Pojo1, Integer>> t2 = new TupleTypeInfo<>(
		BasicTypeInfo.LONG_TYPE_INFO,
		TypeExtractor.getForClass(Pojo1.class),
		BasicTypeInfo.INT_TYPE_INFO);
	TypeInformation<Tuple2<Integer, String>> kt = new TupleTypeInfo<>(
		BasicTypeInfo.INT_TYPE_INFO,
		BasicTypeInfo.STRING_TYPE_INFO
	);

	Keys<PojoWithMultiplePojos> k1 = new Keys.SelectorFunctionKeys<>(
		new KeySelector3(),
		t1,
		kt
	);
	Keys<Tuple3<Long, Pojo1, Integer>> k2 = new Keys.SelectorFunctionKeys<>(
		new KeySelector4(),
		t2,
		kt
	);

	Assert.assertTrue(k1.areCompatible(k2));
	Assert.assertTrue(k2.areCompatible(k1));
}
 
Example 5
Source Project: flink   File: SelectorFunctionKeysTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAreCompatible2() throws Keys.IncompatibleKeysException {
	TypeInformation<PojoWithMultiplePojos> t1 = TypeExtractor.getForClass(PojoWithMultiplePojos.class);
	TypeInformation<Tuple3<Long, Pojo1, Integer>> t2 = new TupleTypeInfo<>(
		BasicTypeInfo.LONG_TYPE_INFO,
		TypeExtractor.getForClass(Pojo1.class),
		BasicTypeInfo.INT_TYPE_INFO);
	TypeInformation<Tuple2<Integer, String>> kt = new TupleTypeInfo<>(
		BasicTypeInfo.INT_TYPE_INFO,
		BasicTypeInfo.STRING_TYPE_INFO
	);

	Keys<PojoWithMultiplePojos> k1 = new Keys.SelectorFunctionKeys<>(
		new KeySelector3(),
		t1,
		kt
	);
	Keys<Tuple3<Long, Pojo1, Integer>> k2 = new Keys.SelectorFunctionKeys<>(
		new KeySelector4(),
		t2,
		kt
	);

	Assert.assertTrue(k1.areCompatible(k2));
	Assert.assertTrue(k2.areCompatible(k1));
}
 
Example 6
Source Project: flink   File: TypeExtractorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTypeInfoFromInstance() {
	ResultTypeQueryable instance = new ResultTypeQueryable<Long>() {
		@Override
		public TypeInformation<Long> getProducedType() {
			return BasicTypeInfo.LONG_TYPE_INFO;
		}
	};
	TypeInformation<?> ti = TypeExtractor.createTypeInfo(instance, null, null, 0);
	Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, ti);

	// method also needs to work for instances that do not implement ResultTypeQueryable
	MapFunction<Integer, Long> func = new MapFunction<Integer, Long>() {
		@Override
		public Long map(Integer value) throws Exception {
			return value.longValue();
		}
	};
	ti = TypeExtractor.createTypeInfo(func, MapFunction.class, func.getClass(), 0);
	Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, ti);
}
 
Example 7
Source Project: flink   File: RetractableTopNFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);

	// compile equaliser
	equaliser = generatedEqualiser.newInstance(getRuntimeContext().getUserCodeClassLoader());
	generatedEqualiser = null;

	ListTypeInfo<RowData> valueTypeInfo = new ListTypeInfo<>(inputRowType);
	MapStateDescriptor<RowData, List<RowData>> mapStateDescriptor = new MapStateDescriptor<>(
			"data-state", sortKeyType, valueTypeInfo);
	dataState = getRuntimeContext().getMapState(mapStateDescriptor);

	ValueStateDescriptor<SortedMap<RowData, Long>> valueStateDescriptor = new ValueStateDescriptor<>(
			"sorted-map",
			new SortedMapTypeInfo<>(sortKeyType, BasicTypeInfo.LONG_TYPE_INFO, serializableComparator));
	treeMap = getRuntimeContext().getState(valueStateDescriptor);
}
 
Example 8
Source Project: Alink   File: JdbcTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Class[] getColTypes() {
	try {
		TypeInformation <?>[] types = this.jdbcDB.getTableSchema(this.tableName).getFieldTypes();
		Class[] comments = new Class[types.length];
		int i = 0;
		for (TypeInformation type : types) {
			if (type == BasicTypeInfo.DOUBLE_TYPE_INFO) {
				comments[i] = Double.class;
			} else if (type == BasicTypeInfo.INT_TYPE_INFO ||
				type == BasicTypeInfo.LONG_TYPE_INFO) {
				comments[i] = Long.class;
			} else if (type == BasicTypeInfo.STRING_TYPE_INFO) {
				comments[i] = String.class;
			} else {

			}
			i++;
		}
		return comments;
	} catch (Exception ex) {
		throw new RuntimeException(ex.getMessage());
	}
}
 
Example 9
@SuppressWarnings("unchecked")
@Test
public void testEitherWithTuple() {

Either<Tuple2<Long, Long>, Double>[] testData = new Either[] {
		Either.Left(new Tuple2<>(2L, 9L)),
		new Left<>(new Tuple2<>(Long.MIN_VALUE, Long.MAX_VALUE)),
		new Right<>(32.0),
		Right(Double.MIN_VALUE),
		Right(Double.MAX_VALUE)};

EitherTypeInfo<Tuple2<Long, Long>, Double> eitherTypeInfo = (EitherTypeInfo<Tuple2<Long, Long>, Double>)
		new EitherTypeInfo<Tuple2<Long, Long>, Double>(
		new TupleTypeInfo<Tuple2<Long, Long>>(BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO),
		BasicTypeInfo.DOUBLE_TYPE_INFO);
EitherSerializer<Tuple2<Long, Long>, Double> eitherSerializer =
		(EitherSerializer<Tuple2<Long, Long>, Double>) eitherTypeInfo.createSerializer(new ExecutionConfig());
SerializerTestInstance<Either<Tuple2<Long, Long>, Double>> testInstance =
		new EitherSerializerTestInstance<Either<Tuple2<Long, Long>, Double>>(
				eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
testInstance.testAll();
}
 
Example 10
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);

	firstStateDesc = new MapStateDescriptor<>(
			"broadcast-state-1", BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO
	);

	secondStateDesc = new MapStateDescriptor<>(
			"broadcast-state-2", BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO
	);
}
 
Example 11
@Test(expected = Keys.IncompatibleKeysException.class)
public void testAreCompatible6() throws Keys.IncompatibleKeysException {
	TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class);
	TypeInformation<Tuple2<String, Long>> t2 = new TupleTypeInfo<>(
		BasicTypeInfo.STRING_TYPE_INFO,
		BasicTypeInfo.LONG_TYPE_INFO
	);

	ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1);
	ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(1, t2);

	ek1.areCompatible(ek2);
}
 
Example 12
Source Project: flink   File: FieldAccessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testIllegalBasicType1() {
	Long x = 7L;
	TypeInformation<Long> tpeInfo = BasicTypeInfo.LONG_TYPE_INFO;

	FieldAccessor<Long, Long> f = FieldAccessorFactory.getAccessor(tpeInfo, 1, null);
}
 
Example 13
Source Project: flink   File: TimeBoundedStreamJoin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	LOGGER.debug("Instantiating JoinFunction: {} \n\n Code:\n{}", genJoinFunc.getClassName(),
			genJoinFunc.getCode());
	joinFunction = genJoinFunc.newInstance(getRuntimeContext().getUserCodeClassLoader());
	genJoinFunc = null;

	joinCollector = new EmitAwareCollector();

	// Initialize the data caches.
	ListTypeInfo<Tuple2<BaseRow, Boolean>> leftRowListTypeInfo = new ListTypeInfo<>(
			new TupleTypeInfo<>(leftType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
	MapStateDescriptor<Long, List<Tuple2<BaseRow, Boolean>>> leftMapStateDescriptor = new MapStateDescriptor<>(
			"WindowJoinLeftCache",
			BasicTypeInfo.LONG_TYPE_INFO,
			leftRowListTypeInfo);
	leftCache = getRuntimeContext().getMapState(leftMapStateDescriptor);

	ListTypeInfo<Tuple2<BaseRow, Boolean>> rightRowListTypeInfo = new ListTypeInfo<>(
			new TupleTypeInfo<>(rightType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
	MapStateDescriptor<Long, List<Tuple2<BaseRow, Boolean>>> rightMapStateDescriptor = new MapStateDescriptor<>(
			"WindowJoinRightCache",
			BasicTypeInfo.LONG_TYPE_INFO,
			rightRowListTypeInfo);
	rightCache = getRuntimeContext().getMapState(rightMapStateDescriptor);

	// Initialize the timer states.
	ValueStateDescriptor<Long> leftValueStateDescriptor = new ValueStateDescriptor<>(
			"WindowJoinLeftTimerState",
			Long.class);
	leftTimerState = getRuntimeContext().getState(leftValueStateDescriptor);

	ValueStateDescriptor<Long> rightValueStateDescriptor = new ValueStateDescriptor<>(
			"WindowJoinRightTimerState",
			Long.class);
	rightTimerState = getRuntimeContext().getState(rightValueStateDescriptor);

	paddingUtil = new OuterJoinPaddingUtil(leftType.getArity(), rightType.getArity());
}
 
Example 14
Source Project: flink   File: HCatInputFormatBase.java    License: Apache License 2.0 5 votes vote down vote up
private TypeInformation getFieldType(HCatFieldSchema fieldSchema) {

		switch(fieldSchema.getType()) {
			case INT:
				return BasicTypeInfo.INT_TYPE_INFO;
			case TINYINT:
				return BasicTypeInfo.BYTE_TYPE_INFO;
			case SMALLINT:
				return BasicTypeInfo.SHORT_TYPE_INFO;
			case BIGINT:
				return BasicTypeInfo.LONG_TYPE_INFO;
			case BOOLEAN:
				return BasicTypeInfo.BOOLEAN_TYPE_INFO;
			case FLOAT:
				return BasicTypeInfo.FLOAT_TYPE_INFO;
			case DOUBLE:
				return BasicTypeInfo.DOUBLE_TYPE_INFO;
			case STRING:
				return BasicTypeInfo.STRING_TYPE_INFO;
			case BINARY:
				return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
			case ARRAY:
				return new GenericTypeInfo(List.class);
			case MAP:
				return new GenericTypeInfo(Map.class);
			case STRUCT:
				return new GenericTypeInfo(List.class);
			default:
				throw new IllegalArgumentException("Unknown data type \"" + fieldSchema.getType() + "\" encountered.");
		}
	}
 
Example 15
Source Project: flink   File: MaxWithRetractAggFunction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MaxWithRetractAccumulator<T> createAccumulator() {
	MaxWithRetractAccumulator<T> acc = new MaxWithRetractAccumulator<>();
	acc.max = null; // max
	acc.mapSize = 0L;
	// store the count for each value
	acc.map = new MapView<>(getValueTypeInfo(), BasicTypeInfo.LONG_TYPE_INFO);
	return acc;
}
 
Example 16
private static TypeSerializer<Row> stringLongRowSupplier() {
	RowTypeInfo rowTypeInfo = new RowTypeInfo(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
	return rowTypeInfo.createSerializer(new ExecutionConfig());
}
 
Example 17
Source Project: flink   File: CoGroupITCase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation[] getKeyTypes() {
	return new TypeInformation[]{BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO};
}
 
Example 18
Source Project: flink   File: OrcBatchReader.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Converts an ORC schema to a Flink TypeInformation.
 *
 * @param schema The ORC schema.
 * @return The TypeInformation that corresponds to the ORC schema.
 */
static TypeInformation schemaToTypeInfo(TypeDescription schema) {
	switch (schema.getCategory()) {
		case BOOLEAN:
			return BasicTypeInfo.BOOLEAN_TYPE_INFO;
		case BYTE:
			return BasicTypeInfo.BYTE_TYPE_INFO;
		case SHORT:
			return BasicTypeInfo.SHORT_TYPE_INFO;
		case INT:
			return BasicTypeInfo.INT_TYPE_INFO;
		case LONG:
			return BasicTypeInfo.LONG_TYPE_INFO;
		case FLOAT:
			return BasicTypeInfo.FLOAT_TYPE_INFO;
		case DOUBLE:
			return BasicTypeInfo.DOUBLE_TYPE_INFO;
		case DECIMAL:
			return BasicTypeInfo.BIG_DEC_TYPE_INFO;
		case STRING:
		case CHAR:
		case VARCHAR:
			return BasicTypeInfo.STRING_TYPE_INFO;
		case DATE:
			return SqlTimeTypeInfo.DATE;
		case TIMESTAMP:
			return SqlTimeTypeInfo.TIMESTAMP;
		case BINARY:
			return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
		case STRUCT:
			List<TypeDescription> fieldSchemas = schema.getChildren();
			TypeInformation[] fieldTypes = new TypeInformation[fieldSchemas.size()];
			for (int i = 0; i < fieldSchemas.size(); i++) {
				fieldTypes[i] = schemaToTypeInfo(fieldSchemas.get(i));
			}
			String[] fieldNames = schema.getFieldNames().toArray(new String[]{});
			return new RowTypeInfo(fieldTypes, fieldNames);
		case LIST:
			TypeDescription elementSchema = schema.getChildren().get(0);
			TypeInformation<?> elementType = schemaToTypeInfo(elementSchema);
			// arrays of primitive types are handled as object arrays to support null values
			return ObjectArrayTypeInfo.getInfoFor(elementType);
		case MAP:
			TypeDescription keySchema = schema.getChildren().get(0);
			TypeDescription valSchema = schema.getChildren().get(1);
			TypeInformation<?> keyType = schemaToTypeInfo(keySchema);
			TypeInformation<?> valType = schemaToTypeInfo(valSchema);
			return new MapTypeInfo<>(keyType, valType);
		case UNION:
			throw new UnsupportedOperationException("UNION type is not supported yet.");
		default:
			throw new IllegalArgumentException("Unknown type " + schema);
	}
}
 
Example 19
@Override
public TypeInformation<Long> getResultType() {
	return BasicTypeInfo.LONG_TYPE_INFO;
}
 
Example 20
Source Project: flink   File: RowCsvInputFormatTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testEmptyFields() throws Exception {
	String fileContent =
		",,,,,,,,\n" +
			",,,,,,,\n" +
			",,,,,,,,\n" +
			",,,,,,,\n" +
			",,,,,,,,\n" +
			",,,,,,,,\n" +
			",,,,,,,\n" +
			",,,,,,,,\n";

	FileInputSplit split = createTempFile(fileContent);

	TypeInformation[] fieldTypes = new TypeInformation[]{
		BasicTypeInfo.BOOLEAN_TYPE_INFO,
		BasicTypeInfo.BYTE_TYPE_INFO,
		BasicTypeInfo.DOUBLE_TYPE_INFO,
		BasicTypeInfo.FLOAT_TYPE_INFO,
		BasicTypeInfo.INT_TYPE_INFO,
		BasicTypeInfo.LONG_TYPE_INFO,
		BasicTypeInfo.SHORT_TYPE_INFO,
		BasicTypeInfo.STRING_TYPE_INFO};

	RowCsvInputFormat format = new RowCsvInputFormat(PATH, fieldTypes, true);
	format.setFieldDelimiter(",");
	format.configure(new Configuration());
	format.open(split);

	Row result = new Row(8);
	int linesCnt = fileContent.split("\n").length;

	for (int i = 0; i < linesCnt; i++) {
		result = format.nextRecord(result);
		assertNull(result.getField(i));
	}

	// ensure no more rows
	assertNull(format.nextRecord(result));
	assertTrue(format.reachedEnd());
}