org.apache.flink.api.java.tuple.Tuple0 Java Examples

The following examples show how to use org.apache.flink.api.java.tuple.Tuple0. 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: TupleSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private <T extends Tuple> void runTests(int length, T... instances) {
	try {
		TupleTypeInfo<T> tupleTypeInfo = (TupleTypeInfo<T>) TypeExtractor.getForObject(instances[0]);
		TypeSerializer<T> serializer = tupleTypeInfo.createSerializer(new ExecutionConfig());
		
		Class<T> tupleClass = tupleTypeInfo.getTypeClass();

		if(tupleClass == Tuple0.class) {
			length = 1;
		}
		SerializerTestInstance<T> test = new SerializerTestInstance<>(serializer, tupleClass, length, instances);
		test.testAll();
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #2
Source File: TypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTuple0() {
	// use getFlatMapReturnTypes()
	RichFlatMapFunction<?, ?> function = new RichFlatMapFunction<Tuple0, Tuple0>() {
		private static final long serialVersionUID = 1L;

		@Override
		public void flatMap(Tuple0 value, Collector<Tuple0> out) throws Exception {
			// nothing to do
		}
	};

	TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(function,
			(TypeInformation) TypeInformation.of(new TypeHint<Tuple0>(){}));

	Assert.assertTrue(ti.isTupleType());
	Assert.assertEquals(0, ti.getArity());
	Assert.assertTrue(ti instanceof TupleTypeInfo);
}
 
Example #3
Source File: TupleSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private <T extends Tuple> void runTests(int length, T... instances) {
	try {
		TupleTypeInfo<T> tupleTypeInfo = (TupleTypeInfo<T>) TypeExtractor.getForObject(instances[0]);
		TypeSerializer<T> serializer = tupleTypeInfo.createSerializer(new ExecutionConfig());
		
		Class<T> tupleClass = tupleTypeInfo.getTypeClass();

		if(tupleClass == Tuple0.class) {
			length = 1;
		}
		SerializerTestInstance<T> test = new SerializerTestInstance<>(serializer, tupleClass, length, instances);
		test.testAll();
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #4
Source File: TupleSerializerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private <T extends Tuple> void runTests(int length, T... instances) {
	try {
		TupleTypeInfo<T> tupleTypeInfo = (TupleTypeInfo<T>) TypeExtractor.getForObject(instances[0]);
		TypeSerializer<T> serializer = tupleTypeInfo.createSerializer(new ExecutionConfig());
		
		Class<T> tupleClass = tupleTypeInfo.getTypeClass();

		if(tupleClass == Tuple0.class) {
			length = 1;
		}
		SerializerTestInstance<T> test = new SerializerTestInstance<>(serializer, tupleClass, length, instances);
		test.testAll();
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #5
Source File: TypeExtractorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTuple0() {
	// use getFlatMapReturnTypes()
	RichFlatMapFunction<?, ?> function = new RichFlatMapFunction<Tuple0, Tuple0>() {
		private static final long serialVersionUID = 1L;

		@Override
		public void flatMap(Tuple0 value, Collector<Tuple0> out) throws Exception {
			// nothing to do
		}
	};

	TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(function,
			(TypeInformation) TypeInformation.of(new TypeHint<Tuple0>(){}));

	Assert.assertTrue(ti.isTupleType());
	Assert.assertEquals(0, ti.getArity());
	Assert.assertTrue(ti instanceof TupleTypeInfo);
}
 
Example #6
Source File: TypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTuple0() {
	// use getFlatMapReturnTypes()
	RichFlatMapFunction<?, ?> function = new RichFlatMapFunction<Tuple0, Tuple0>() {
		private static final long serialVersionUID = 1L;

		@Override
		public void flatMap(Tuple0 value, Collector<Tuple0> out) throws Exception {
			// nothing to do
		}
	};

	TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(function,
			(TypeInformation) TypeInformation.of(new TypeHint<Tuple0>(){}));

	Assert.assertTrue(ti.isTupleType());
	Assert.assertEquals(0, ti.getArity());
	Assert.assertTrue(ti instanceof TupleTypeInfo);
}
 
Example #7
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Tuple0> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<Tuple0> deprecatedConfigSnapshot) {

	Tuple0SerializerSnapshot snapshot = new Tuple0SerializerSnapshot();
	return snapshot.resolveSchemaCompatibility(this);
}
 
Example #8
Source File: Tuple0Serializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Tuple0> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<Tuple0> deprecatedConfigSnapshot) {

	Tuple0SerializerSnapshot snapshot = new Tuple0SerializerSnapshot();
	return snapshot.resolveSchemaCompatibility(this);
}
 
Example #9
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializerSchemaCompatibility<Tuple0> resolveSchemaCompatibilityViaRedirectingToNewSnapshotClass(
		TypeSerializerConfigSnapshot<Tuple0> deprecatedConfigSnapshot) {

	Tuple0SerializerSnapshot snapshot = new Tuple0SerializerSnapshot();
	return snapshot.resolveSchemaCompatibility(this);
}
 
Example #10
Source File: Tuple0Serializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple0 createInstance(Object[] fields) {
	if (fields == null || fields.length == 0) {
		return Tuple0.INSTANCE;
	}

	throw new UnsupportedOperationException(
			"Tuple0 cannot take any data, as it has zero fields.");
}
 
Example #11
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple0 createInstance(Object[] fields) {
	if (fields == null || fields.length == 0) {
		return Tuple0.INSTANCE;
	}

	throw new UnsupportedOperationException(
			"Tuple0 cannot take any data, as it has zero fields.");
}
 
Example #12
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple0 createInstance(Object[] fields) {
	if (fields == null || fields.length == 0) {
		return Tuple0.INSTANCE;
	}

	throw new UnsupportedOperationException(
			"Tuple0 cannot take any data, as it has zero fields.");
}
 
Example #13
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 copy(Tuple0 from) {
	return from;
}
 
Example #14
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSnapshot<Tuple0> snapshotConfiguration() {
	return new Tuple0SerializerSnapshot();
}
 
Example #15
Source File: TupleSerializerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testTuple0() {
	Tuple0[] testTuples = new Tuple0[] { Tuple0.INSTANCE, Tuple0.INSTANCE, Tuple0.INSTANCE };

	runTests(1, testTuples);
}
 
Example #16
Source File: SiddhiTupleFactory.java    From flink-siddhi with Apache License 2.0 4 votes vote down vote up
/**
 * Convert object array to type of Tuple{N} where N is between 0 to 25.
 *
 * @throws IllegalArgumentException if rows's length > 25
 */
public static <T extends Tuple> T newTuple(Object[] row) {
    Preconditions.checkNotNull(row, "Tuple row is null");
    switch (row.length) {
        case 0:
            return setTupleValue(new Tuple0(), row);
        case 1:
            return setTupleValue(new Tuple1(), row);
        case 2:
            return setTupleValue(new Tuple2(), row);
        case 3:
            return setTupleValue(new Tuple3(), row);
        case 4:
            return setTupleValue(new Tuple4(), row);
        case 5:
            return setTupleValue(new Tuple5(), row);
        case 6:
            return setTupleValue(new Tuple6(), row);
        case 7:
            return setTupleValue(new Tuple7(), row);
        case 8:
            return setTupleValue(new Tuple8(), row);
        case 9:
            return setTupleValue(new Tuple9(), row);
        case 10:
            return setTupleValue(new Tuple10(), row);
        case 11:
            return setTupleValue(new Tuple11(), row);
        case 12:
            return setTupleValue(new Tuple12(), row);
        case 13:
            return setTupleValue(new Tuple13(), row);
        case 14:
            return setTupleValue(new Tuple14(), row);
        case 15:
            return setTupleValue(new Tuple15(), row);
        case 16:
            return setTupleValue(new Tuple16(), row);
        case 17:
            return setTupleValue(new Tuple17(), row);
        case 18:
            return setTupleValue(new Tuple18(), row);
        case 19:
            return setTupleValue(new Tuple19(), row);
        case 20:
            return setTupleValue(new Tuple20(), row);
        case 21:
            return setTupleValue(new Tuple21(), row);
        case 22:
            return setTupleValue(new Tuple22(), row);
        case 23:
            return setTupleValue(new Tuple23(), row);
        case 24:
            return setTupleValue(new Tuple24(), row);
        case 25:
            return setTupleValue(new Tuple25(), row);
        default:
            throw new IllegalArgumentException("Too long row: " + row.length + ", unable to convert to Tuple");
    }
}
 
Example #17
Source File: SiddhiTupleFactory.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
/**
 * Convert object array to type of Tuple{N} where N is between 0 to 25.
 *
 * @throws IllegalArgumentException if rows's length > 25
 */
public static <T extends Tuple> T newTuple(Object[] row) {
    Preconditions.checkNotNull(row, "Tuple row is null");
    switch (row.length) {
        case 0:
            return setTupleValue(new Tuple0(), row);
        case 1:
            return setTupleValue(new Tuple1<>(), row);
        case 2:
            return setTupleValue(new Tuple2<>(), row);
        case 3:
            return setTupleValue(new Tuple3<>(), row);
        case 4:
            return setTupleValue(new Tuple4<>(), row);
        case 5:
            return setTupleValue(new Tuple5<>(), row);
        case 6:
            return setTupleValue(new Tuple6<>(), row);
        case 7:
            return setTupleValue(new Tuple7<>(), row);
        case 8:
            return setTupleValue(new Tuple8<>(), row);
        case 9:
            return setTupleValue(new Tuple9<>(), row);
        case 10:
            return setTupleValue(new Tuple10<>(), row);
        case 11:
            return setTupleValue(new Tuple11<>(), row);
        case 12:
            return setTupleValue(new Tuple12<>(), row);
        case 13:
            return setTupleValue(new Tuple13<>(), row);
        case 14:
            return setTupleValue(new Tuple14<>(), row);
        case 15:
            return setTupleValue(new Tuple15<>(), row);
        case 16:
            return setTupleValue(new Tuple16<>(), row);
        case 17:
            return setTupleValue(new Tuple17<>(), row);
        case 18:
            return setTupleValue(new Tuple18<>(), row);
        case 19:
            return setTupleValue(new Tuple19<>(), row);
        case 20:
            return setTupleValue(new Tuple20<>(), row);
        case 21:
            return setTupleValue(new Tuple21<>(), row);
        case 22:
            return setTupleValue(new Tuple22<>(), row);
        case 23:
            return setTupleValue(new Tuple23<>(), row);
        case 24:
            return setTupleValue(new Tuple24<>(), row);
        case 25:
            return setTupleValue(new Tuple25<>(), row);
        default:
            throw new IllegalArgumentException("Too long row: " + row.length + ", unable to convert to Tuple");
    }
}
 
Example #18
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
private Tuple0Serializer() {
	super(Tuple0.class, new TypeSerializer<?>[0]);
}
 
Example #19
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 createInstance() {
	return Tuple0.INSTANCE;
}
 
Example #20
Source File: Tuple0Builder.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple0[] build() {
	return tuples.toArray(new Tuple0[tuples.size()]);
}
 
Example #21
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 copy(Tuple0 from, Tuple0 reuse) {
	return reuse;
}
 
Example #22
Source File: TupleSerializerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testTuple0() {
	Tuple0[] testTuples = new Tuple0[] { Tuple0.INSTANCE, Tuple0.INSTANCE, Tuple0.INSTANCE };

	runTests(1, testTuples);
}
 
Example #23
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Tuple0 record, DataOutputView target) throws IOException {
	Preconditions.checkNotNull(record);
	target.writeByte(42);
}
 
Example #24
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 deserialize(DataInputView source) throws IOException {
	source.readByte();
	return Tuple0.INSTANCE;
}
 
Example #25
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 deserialize(Tuple0 reuse, DataInputView source) throws IOException {
	source.readByte();
	return reuse;
}
 
Example #26
Source File: Tuple0Serializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSnapshot<Tuple0> snapshotConfiguration() {
	return new Tuple0SerializerSnapshot();
}
 
Example #27
Source File: Tuple0Builder.java    From flink with Apache License 2.0 4 votes vote down vote up
public Tuple0Builder add() {
	tuples.add(Tuple0.INSTANCE);
	return this;
}
 
Example #28
Source File: TupleSerializerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testTuple0() {
	Tuple0[] testTuples = new Tuple0[] { Tuple0.INSTANCE, Tuple0.INSTANCE, Tuple0.INSTANCE };

	runTests(1, testTuples);
}
 
Example #29
Source File: Tuple0Serializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 createInstance() {
	return Tuple0.INSTANCE;
}
 
Example #30
Source File: Tuple0Serializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public Tuple0 copy(Tuple0 from) {
	return from;
}