use of org.apache.flink.api.java.functions.KeySelector in project flink by apache.
the class PartitionOperatorTest method testRangePartitionBySelectorComplexKeyWithTooManyOrders.
@Test(expected = IllegalArgumentException.class)
public void testRangePartitionBySelectorComplexKeyWithTooManyOrders() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
final DataSet<NestedPojo> ds = getNestedPojoDataSet(env);
ds.partitionByRange(new KeySelector<NestedPojo, CustomPojo>() {
@Override
public CustomPojo getKey(NestedPojo value) throws Exception {
return value.getNested();
}
}).withOrders(Order.ASCENDING, Order.DESCENDING);
}
use of org.apache.flink.api.java.functions.KeySelector in project flink by apache.
the class GroupingTest method testGroupSortByKeySelector3.
@SuppressWarnings("serial")
@Test(expected = InvalidProgramException.class)
public void testGroupSortByKeySelector3() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple4<Integer, Long, CustomType, Long[]>> tupleDs = env.fromCollection(tupleWithCustomData, tupleWithCustomInfo);
// should not work
tupleDs.groupBy(new KeySelector<Tuple4<Integer, Long, CustomType, Long[]>, Long>() {
@Override
public Long getKey(Tuple4<Integer, Long, CustomType, Long[]> value) throws Exception {
return value.f1;
}
}).sortGroup(new KeySelector<Tuple4<Integer, Long, CustomType, Long[]>, Long[]>() {
@Override
public Long[] getKey(Tuple4<Integer, Long, CustomType, Long[]> value) throws Exception {
return value.f3;
}
}, Order.ASCENDING);
}
use of org.apache.flink.api.java.functions.KeySelector in project flink by apache.
the class JoinOperatorTest method testJoinProjection26.
@Test
public void testJoinProjection26() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CustomType> ds1 = env.fromCollection(customTypeData);
DataSet<CustomType> ds2 = env.fromCollection(customTypeData);
// should work
try {
ds1.join(ds2).where(new KeySelector<CustomType, Long>() {
@Override
public Long getKey(CustomType value) {
return value.myLong;
}
}).equalTo(new KeySelector<CustomType, Long>() {
@Override
public Long getKey(CustomType value) {
return value.myLong;
}
}).projectFirst().projectSecond();
} catch (Exception e) {
System.out.println("FAILED: " + e);
e.printStackTrace();
Assert.fail();
}
}
use of org.apache.flink.api.java.functions.KeySelector in project flink by apache.
the class JoinOperatorTest method testJoinKeyMixedKeySelectorTurned.
@Test
public void testJoinKeyMixedKeySelectorTurned() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CustomType> ds1 = env.fromCollection(customTypeData);
DataSet<CustomType> ds2 = env.fromCollection(customTypeData);
try {
ds1.join(ds2).where(new KeySelector<CustomType, Integer>() {
@Override
public Integer getKey(CustomType value) throws Exception {
return value.myInt;
}
}).equalTo("myInt");
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
use of org.apache.flink.api.java.functions.KeySelector in project flink by apache.
the class JoinOperatorTest method testJoinKeyMixing1.
@Test
public void testJoinKeyMixing1() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CustomType> ds1 = env.fromCollection(customTypeData);
DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);
// should work
try {
ds1.join(ds2).where(new KeySelector<CustomType, Long>() {
@Override
public Long getKey(CustomType value) {
return value.myLong;
}
}).equalTo(3);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
Aggregations