Java Code Examples for org.apache.flink.api.java.tuple.Tuple#MAX_ARITY

The following examples show how to use org.apache.flink.api.java.tuple.Tuple#MAX_ARITY . 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: StreamProjection.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
protected StreamProjection(DataStream<IN> dataStream, int[] fieldIndexes) {
	if (!dataStream.getType().isTupleType()) {
		throw new RuntimeException("Only Tuple DataStreams can be projected");
	}
	if (fieldIndexes.length == 0) {
		throw new IllegalArgumentException("project() needs to select at least one (1) field.");
	} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
		throw new IllegalArgumentException(
				"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
	}

	int maxFieldIndex = (dataStream.getType()).getArity();
	for (int i = 0; i < fieldIndexes.length; i++) {
		Preconditions.checkElementIndex(fieldIndexes[i], maxFieldIndex);
	}

	this.dataStream = dataStream;
	this.fieldIndexes = fieldIndexes;
}
 
Example 2
Source File: ProjectOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public Projection(DataSet<T> ds, int[] fieldIndexes) {

			if (!(ds.getType() instanceof TupleTypeInfo)) {
				throw new UnsupportedOperationException("project() can only be applied to DataSets of Tuples.");
			}

			if (fieldIndexes.length == 0) {
				throw new IllegalArgumentException("project() needs to select at least one (1) field.");
			} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
				throw new IllegalArgumentException(
					"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
			}

			int maxFieldIndex = ds.getType().getArity();
			for (int fieldIndexe : fieldIndexes) {
				Preconditions.checkElementIndex(fieldIndexe, maxFieldIndex);
			}

			this.ds = ds;
			this.fieldIndexes = fieldIndexes;
		}
 
Example 3
Source File: KeySelectorUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) {
	if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) {
		throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields.");
	}

	TypeInformation<?> componentType;

	if (typeInfo instanceof BasicArrayTypeInfo) {
		BasicArrayTypeInfo<X, ?>  arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo;
		componentType = arrayInfo.getComponentInfo();
	}
	else if (typeInfo instanceof PrimitiveArrayTypeInfo) {
		PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo;
		componentType = arrayType.getComponentType();
	}
	else {
		throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives.");
	}

	TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length];
	Arrays.fill(primitiveInfos, componentType);

	return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos));
}
 
Example 4
Source File: StreamProjection.java    From flink with Apache License 2.0 6 votes vote down vote up
protected StreamProjection(DataStream<IN> dataStream, int[] fieldIndexes) {
	if (!dataStream.getType().isTupleType()) {
		throw new RuntimeException("Only Tuple DataStreams can be projected");
	}
	if (fieldIndexes.length == 0) {
		throw new IllegalArgumentException("project() needs to select at least one (1) field.");
	} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
		throw new IllegalArgumentException(
				"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
	}

	int maxFieldIndex = (dataStream.getType()).getArity();
	for (int i = 0; i < fieldIndexes.length; i++) {
		Preconditions.checkElementIndex(fieldIndexes[i], maxFieldIndex);
	}

	this.dataStream = dataStream;
	this.fieldIndexes = fieldIndexes;
}
 
Example 5
Source File: ProjectOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public Projection(DataSet<T> ds, int[] fieldIndexes) {

			if (!(ds.getType() instanceof TupleTypeInfo)) {
				throw new UnsupportedOperationException("project() can only be applied to DataSets of Tuples.");
			}

			if (fieldIndexes.length == 0) {
				throw new IllegalArgumentException("project() needs to select at least one (1) field.");
			} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
				throw new IllegalArgumentException(
					"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
			}

			int maxFieldIndex = ds.getType().getArity();
			for (int fieldIndexe : fieldIndexes) {
				Preconditions.checkElementIndex(fieldIndexe, maxFieldIndex);
			}

			this.ds = ds;
			this.fieldIndexes = fieldIndexes;
		}
 
Example 6
Source File: KeySelectorUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) {
	if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) {
		throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields.");
	}

	TypeInformation<?> componentType;

	if (typeInfo instanceof BasicArrayTypeInfo) {
		BasicArrayTypeInfo<X, ?>  arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo;
		componentType = arrayInfo.getComponentInfo();
	}
	else if (typeInfo instanceof PrimitiveArrayTypeInfo) {
		PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo;
		componentType = arrayType.getComponentType();
	}
	else {
		throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives.");
	}

	TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length];
	Arrays.fill(primitiveInfos, componentType);

	return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos));
}
 
Example 7
Source File: KeySelectorUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) {
	if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) {
		throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields.");
	}

	TypeInformation<?> componentType;

	if (typeInfo instanceof BasicArrayTypeInfo) {
		BasicArrayTypeInfo<X, ?>  arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo;
		componentType = arrayInfo.getComponentInfo();
	}
	else if (typeInfo instanceof PrimitiveArrayTypeInfo) {
		PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo;
		componentType = arrayType.getComponentType();
	}
	else {
		throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives.");
	}

	TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length];
	Arrays.fill(primitiveInfos, componentType);

	return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos));
}
 
Example 8
Source File: ProjectOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public Projection(DataSet<T> ds, int[] fieldIndexes) {

			if (!(ds.getType() instanceof TupleTypeInfo)) {
				throw new UnsupportedOperationException("project() can only be applied to DataSets of Tuples.");
			}

			if (fieldIndexes.length == 0) {
				throw new IllegalArgumentException("project() needs to select at least one (1) field.");
			} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
				throw new IllegalArgumentException(
					"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
			}

			int maxFieldIndex = ds.getType().getArity();
			for (int fieldIndexe : fieldIndexes) {
				Preconditions.checkElementIndex(fieldIndexe, maxFieldIndex);
			}

			this.ds = ds;
			this.fieldIndexes = fieldIndexes;
		}
 
Example 9
Source File: FieldsFromTupleTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	testDouble = new double[Tuple.MAX_ARITY];
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		testDouble[i] = i;
	}
}
 
Example 10
Source File: FieldsFromTupleTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserSpecifiedOrder() throws InstantiationException, IllegalAccessException {
	Tuple currentTuple = (Tuple) CLASSES[Tuple.MAX_ARITY - 1].newInstance();
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		currentTuple.setField(testDouble[i], i);
	}

	double[] expected = { testDouble[5], testDouble[3], testDouble[6], testDouble[7],
			testDouble[0] };
	arrayEqualityCheck(expected, new FieldsFromTuple(5, 3, 6, 7, 0).extract(currentTuple));

	double[] expected2 = { testDouble[0], testDouble[Tuple.MAX_ARITY - 1] };
	arrayEqualityCheck(expected2,
			new FieldsFromTuple(0, Tuple.MAX_ARITY - 1).extract(currentTuple));

	double[] expected3 = { testDouble[Tuple.MAX_ARITY - 1], testDouble[0] };
	arrayEqualityCheck(expected3,
			new FieldsFromTuple(Tuple.MAX_ARITY - 1, 0).extract(currentTuple));

	double[] expected4 = { testDouble[13], testDouble[4], testDouble[5], testDouble[4],
			testDouble[2], testDouble[8], testDouble[6], testDouble[2], testDouble[8],
			testDouble[3], testDouble[5], testDouble[2], testDouble[16], testDouble[4],
			testDouble[3], testDouble[2], testDouble[6], testDouble[4], testDouble[7],
			testDouble[4], testDouble[2], testDouble[8], testDouble[7], testDouble[2] };
	arrayEqualityCheck(expected4, new FieldsFromTuple(13, 4, 5, 4, 2, 8, 6, 2, 8, 3, 5, 2, 16,
			4, 3, 2, 6, 4, 7, 4, 2, 8, 7, 2).extract(currentTuple));
}
 
Example 11
Source File: FieldFromTupleTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	testStrings = new String[Tuple.MAX_ARITY];
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		testStrings[i] = Integer.toString(i);
	}
}
 
Example 12
Source File: FieldFromTupleTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleFieldExtraction() throws InstantiationException, IllegalAccessException {
	// extract single fields
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		Tuple current = (Tuple) CLASSES[i].newInstance();
		for (int j = 0; j < i; j++) {
			current.setField(testStrings[j], j);
		}
		for (int j = 0; j < i; j++) {
			assertEquals(testStrings[j], new FieldFromTuple<String>(j).extract(current));
		}
	}
}
 
Example 13
Source File: ArrayFromTupleTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertFromTupleToArray() throws InstantiationException, IllegalAccessException {
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		Tuple currentTuple = (Tuple) CLASSES[i].newInstance();
		String[] currentArray = new String[i + 1];
		for (int j = 0; j <= i; j++) {
			currentTuple.setField(testStrings[j], j);
			currentArray[j] = testStrings[j];
		}
		arrayEqualityCheck(currentArray, new ArrayFromTuple().extract(currentTuple));
	}
}
 
Example 14
Source File: FieldsFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserSpecifiedOrder() throws InstantiationException, IllegalAccessException {
	Tuple currentTuple = (Tuple) CLASSES[Tuple.MAX_ARITY - 1].newInstance();
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		currentTuple.setField(testDouble[i], i);
	}

	double[] expected = { testDouble[5], testDouble[3], testDouble[6], testDouble[7],
			testDouble[0] };
	arrayEqualityCheck(expected, new FieldsFromTuple(5, 3, 6, 7, 0).extract(currentTuple));

	double[] expected2 = { testDouble[0], testDouble[Tuple.MAX_ARITY - 1] };
	arrayEqualityCheck(expected2,
			new FieldsFromTuple(0, Tuple.MAX_ARITY - 1).extract(currentTuple));

	double[] expected3 = { testDouble[Tuple.MAX_ARITY - 1], testDouble[0] };
	arrayEqualityCheck(expected3,
			new FieldsFromTuple(Tuple.MAX_ARITY - 1, 0).extract(currentTuple));

	double[] expected4 = { testDouble[13], testDouble[4], testDouble[5], testDouble[4],
			testDouble[2], testDouble[8], testDouble[6], testDouble[2], testDouble[8],
			testDouble[3], testDouble[5], testDouble[2], testDouble[16], testDouble[4],
			testDouble[3], testDouble[2], testDouble[6], testDouble[4], testDouble[7],
			testDouble[4], testDouble[2], testDouble[8], testDouble[7], testDouble[2] };
	arrayEqualityCheck(expected4, new FieldsFromTuple(13, 4, 5, 4, 2, 8, 6, 2, 8, 3, 5, 2, 16,
			4, 3, 2, 6, 4, 7, 4, 2, 8, 7, 2).extract(currentTuple));
}
 
Example 15
Source File: ArrayFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	testStrings = new String[Tuple.MAX_ARITY];
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		testStrings[i] = Integer.toString(i);
	}
}
 
Example 16
Source File: ArrayFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertFromTupleToArray() throws InstantiationException, IllegalAccessException {
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		Tuple currentTuple = (Tuple) CLASSES[i].newInstance();
		String[] currentArray = new String[i + 1];
		for (int j = 0; j <= i; j++) {
			currentTuple.setField(testStrings[j], j);
			currentArray[j] = testStrings[j];
		}
		arrayEqualityCheck(currentArray, new ArrayFromTuple().extract(currentTuple));
	}
}
 
Example 17
Source File: ArrayFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertFromTupleToArray() throws InstantiationException, IllegalAccessException {
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		Tuple currentTuple = (Tuple) CLASSES[i].newInstance();
		String[] currentArray = new String[i + 1];
		for (int j = 0; j <= i; j++) {
			currentTuple.setField(testStrings[j], j);
			currentArray[j] = testStrings[j];
		}
		arrayEqualityCheck(currentArray, new ArrayFromTuple().extract(currentTuple));
	}
}
 
Example 18
Source File: ArrayFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	testStrings = new String[Tuple.MAX_ARITY];
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		testStrings[i] = Integer.toString(i);
	}
}
 
Example 19
Source File: FieldFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	testStrings = new String[Tuple.MAX_ARITY];
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		testStrings[i] = Integer.toString(i);
	}
}
 
Example 20
Source File: FieldFromTupleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleFieldExtraction() throws InstantiationException, IllegalAccessException {
	// extract single fields
	for (int i = 0; i < Tuple.MAX_ARITY; i++) {
		Tuple current = (Tuple) CLASSES[i].newInstance();
		for (int j = 0; j < i; j++) {
			current.setField(testStrings[j], j);
		}
		for (int j = 0; j < i; j++) {
			assertEquals(testStrings[j], new FieldFromTuple<String>(j).extract(current));
		}
	}
}