use of org.apache.flink.api.common.operators.Ordering in project flink by apache.
the class RequestedLocalPropertiesFilteringTest method testOrderPreserved1.
@Test
public void testOrderPreserved1() {
SingleInputSemanticProperties sProps = new SingleInputSemanticProperties();
SemanticPropUtil.getSemanticPropsSingleFromString(sProps, new String[] { "1;4;6" }, null, null, tupleInfo, tupleInfo);
Ordering o = new Ordering();
o.appendOrdering(4, LongValue.class, Order.DESCENDING);
o.appendOrdering(1, IntValue.class, Order.ASCENDING);
o.appendOrdering(6, ByteValue.class, Order.DESCENDING);
RequestedLocalProperties rlProp = new RequestedLocalProperties();
rlProp.setOrdering(o);
RequestedLocalProperties filtered = rlProp.filterBySemanticProperties(sProps, 0);
assertNotNull(filtered);
assertNotNull(filtered.getOrdering());
assertEquals(3, filtered.getOrdering().getNumberOfFields());
assertEquals(4, filtered.getOrdering().getFieldNumber(0).intValue());
assertEquals(1, filtered.getOrdering().getFieldNumber(1).intValue());
assertEquals(6, filtered.getOrdering().getFieldNumber(2).intValue());
assertEquals(LongValue.class, filtered.getOrdering().getType(0));
assertEquals(IntValue.class, filtered.getOrdering().getType(1));
assertEquals(ByteValue.class, filtered.getOrdering().getType(2));
assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(0));
assertEquals(Order.ASCENDING, filtered.getOrdering().getOrder(1));
assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(2));
assertNull(filtered.getGroupedFields());
}
use of org.apache.flink.api.common.operators.Ordering in project flink by apache.
the class RequestedLocalPropertiesFilteringTest method testOrderPreserved2.
@Test
public void testOrderPreserved2() {
SingleInputSemanticProperties sProps = new SingleInputSemanticProperties();
SemanticPropUtil.getSemanticPropsSingleFromString(sProps, new String[] { "5->1;0->4;2->6" }, null, null, tupleInfo, tupleInfo);
Ordering o = new Ordering();
o.appendOrdering(4, LongValue.class, Order.DESCENDING);
o.appendOrdering(1, IntValue.class, Order.ASCENDING);
o.appendOrdering(6, ByteValue.class, Order.DESCENDING);
RequestedLocalProperties rlProp = new RequestedLocalProperties();
rlProp.setOrdering(o);
RequestedLocalProperties filtered = rlProp.filterBySemanticProperties(sProps, 0);
assertNotNull(filtered);
assertNotNull(filtered.getOrdering());
assertEquals(3, filtered.getOrdering().getNumberOfFields());
assertEquals(0, filtered.getOrdering().getFieldNumber(0).intValue());
assertEquals(5, filtered.getOrdering().getFieldNumber(1).intValue());
assertEquals(2, filtered.getOrdering().getFieldNumber(2).intValue());
assertEquals(LongValue.class, filtered.getOrdering().getType(0));
assertEquals(IntValue.class, filtered.getOrdering().getType(1));
assertEquals(ByteValue.class, filtered.getOrdering().getType(2));
assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(0));
assertEquals(Order.ASCENDING, filtered.getOrdering().getOrder(1));
assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(2));
assertNull(filtered.getGroupedFields());
}
use of org.apache.flink.api.common.operators.Ordering in project flink by apache.
the class GlobalPropertiesMatchingTest method testMatchingAnyPartitioning.
@Test
public void testMatchingAnyPartitioning() {
try {
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setAnyPartitioning(new FieldSet(6, 2));
// match any partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setAnyPartitioning(new FieldList(2, 6));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setAnyPartitioning(new FieldList(6, 2));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setAnyPartitioning(new FieldList(6, 2, 4));
assertFalse(req.isMetBy(gp3));
GlobalProperties gp4 = new GlobalProperties();
gp4.setAnyPartitioning(new FieldList(6, 1));
assertFalse(req.isMetBy(gp4));
GlobalProperties gp5 = new GlobalProperties();
gp5.setAnyPartitioning(new FieldList(2));
assertTrue(req.isMetBy(gp5));
}
// match hash partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setHashPartitioned(new FieldList(2, 6));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setHashPartitioned(new FieldList(6, 2));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setHashPartitioned(new FieldList(6, 1));
assertFalse(req.isMetBy(gp3));
}
// match range partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setRangePartitioned(new Ordering(2, null, Order.DESCENDING).appendOrdering(6, null, Order.ASCENDING));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setRangePartitioned(new Ordering(6, null, Order.DESCENDING).appendOrdering(2, null, Order.ASCENDING));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setRangePartitioned(new Ordering(6, null, Order.DESCENDING).appendOrdering(1, null, Order.ASCENDING));
assertFalse(req.isMetBy(gp3));
GlobalProperties gp4 = new GlobalProperties();
gp4.setRangePartitioned(new Ordering(6, null, Order.DESCENDING));
assertTrue(req.isMetBy(gp4));
}
// match custom partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setCustomPartitioned(new FieldList(2, 6), new MockPartitioner());
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setCustomPartitioned(new FieldList(6, 2), new MockPartitioner());
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setCustomPartitioned(new FieldList(6, 1), new MockPartitioner());
assertFalse(req.isMetBy(gp3));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.Ordering in project flink by apache.
the class GlobalPropertiesMatchingTest method testMatchingCustomPartitioning.
@Test
public void testMatchingCustomPartitioning() {
try {
final Partitioner<Tuple2<Long, Integer>> partitioner = new MockPartitioner();
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setCustomPartitioned(new FieldSet(6, 2), partitioner);
// match custom partitionings
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setCustomPartitioned(new FieldList(2, 6), partitioner);
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setCustomPartitioned(new FieldList(6, 2), partitioner);
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setCustomPartitioned(new FieldList(6, 2), new MockPartitioner());
assertFalse(req.isMetBy(gp3));
}
// cannot match other types of partitionings
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setAnyPartitioning(new FieldList(6, 2));
assertFalse(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setHashPartitioned(new FieldList(6, 2));
assertFalse(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setRangePartitioned(new Ordering(2, null, Order.DESCENDING).appendOrdering(6, null, Order.ASCENDING));
assertFalse(req.isMetBy(gp3));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.Ordering in project flink by apache.
the class JoinGlobalPropertiesCompatibilityTest method checkInompatiblePartitionings.
@Test
public void checkInompatiblePartitionings() {
try {
final FieldList keysLeft = new FieldList(1);
final FieldList keysRight = new FieldList(3);
final Partitioner<Object> part = new Partitioner<Object>() {
@Override
public int partition(Object key, int numPartitions) {
return 0;
}
};
final Partitioner<Object> part2 = new Partitioner<Object>() {
@Override
public int partition(Object key, int numPartitions) {
return 0;
}
};
SortMergeInnerJoinDescriptor descr = new SortMergeInnerJoinDescriptor(keysLeft, keysRight);
// test incompatible hash with custom partitioning
{
RequestedGlobalProperties reqLeft = new RequestedGlobalProperties();
reqLeft.setAnyPartitioning(keysLeft);
RequestedGlobalProperties reqRight = new RequestedGlobalProperties();
reqRight.setAnyPartitioning(keysRight);
GlobalProperties propsLeft = new GlobalProperties();
propsLeft.setHashPartitioned(keysLeft);
GlobalProperties propsRight = new GlobalProperties();
propsRight.setCustomPartitioned(keysRight, part);
assertFalse(descr.areCompatible(reqLeft, reqRight, propsLeft, propsRight));
}
// test incompatible custom partitionings
{
RequestedGlobalProperties reqLeft = new RequestedGlobalProperties();
reqLeft.setAnyPartitioning(keysLeft);
RequestedGlobalProperties reqRight = new RequestedGlobalProperties();
reqRight.setAnyPartitioning(keysRight);
GlobalProperties propsLeft = new GlobalProperties();
propsLeft.setCustomPartitioned(keysLeft, part);
GlobalProperties propsRight = new GlobalProperties();
propsRight.setCustomPartitioned(keysRight, part2);
assertFalse(descr.areCompatible(reqLeft, reqRight, propsLeft, propsRight));
}
TestDistribution dist1 = new TestDistribution(1);
TestDistribution dist2 = new TestDistribution(1);
// test incompatible range partitioning with different key size
{
Ordering ordering1 = new Ordering();
for (int field : keysLeft) {
ordering1.appendOrdering(field, null, Order.ASCENDING);
}
Ordering ordering2 = new Ordering();
for (int field : keysRight) {
ordering1.appendOrdering(field, null, Order.ASCENDING);
ordering2.appendOrdering(field, null, Order.ASCENDING);
}
RequestedGlobalProperties reqLeft = new RequestedGlobalProperties();
reqLeft.setRangePartitioned(ordering1, dist1);
RequestedGlobalProperties reqRight = new RequestedGlobalProperties();
reqRight.setRangePartitioned(ordering2, dist2);
GlobalProperties propsLeft = new GlobalProperties();
propsLeft.setRangePartitioned(ordering1, dist1);
GlobalProperties propsRight = new GlobalProperties();
propsRight.setRangePartitioned(ordering2, dist2);
assertFalse(descr.areCompatible(reqLeft, reqRight, propsLeft, propsRight));
}
// test incompatible range partitioning with different ordering
{
Ordering ordering1 = new Ordering();
for (int field : keysLeft) {
ordering1.appendOrdering(field, null, Order.ASCENDING);
}
Ordering ordering2 = new Ordering();
for (int field : keysRight) {
ordering2.appendOrdering(field, null, Order.DESCENDING);
}
RequestedGlobalProperties reqLeft = new RequestedGlobalProperties();
reqLeft.setRangePartitioned(ordering1, dist1);
RequestedGlobalProperties reqRight = new RequestedGlobalProperties();
reqRight.setRangePartitioned(ordering2, dist2);
GlobalProperties propsLeft = new GlobalProperties();
propsLeft.setRangePartitioned(ordering1, dist1);
GlobalProperties propsRight = new GlobalProperties();
propsRight.setRangePartitioned(ordering2, dist2);
assertFalse(descr.areCompatible(reqLeft, reqRight, propsLeft, propsRight));
}
TestDistribution dist3 = new TestDistribution(1);
TestDistribution dist4 = new TestDistribution(2);
// test incompatible range partitioning with different distribution
{
Ordering ordering1 = new Ordering();
for (int field : keysLeft) {
ordering1.appendOrdering(field, null, Order.ASCENDING);
}
Ordering ordering2 = new Ordering();
for (int field : keysRight) {
ordering2.appendOrdering(field, null, Order.ASCENDING);
}
RequestedGlobalProperties reqLeft = new RequestedGlobalProperties();
reqLeft.setRangePartitioned(ordering1, dist3);
RequestedGlobalProperties reqRight = new RequestedGlobalProperties();
reqRight.setRangePartitioned(ordering2, dist4);
GlobalProperties propsLeft = new GlobalProperties();
propsLeft.setRangePartitioned(ordering1, dist3);
GlobalProperties propsRight = new GlobalProperties();
propsRight.setRangePartitioned(ordering2, dist4);
assertFalse(descr.areCompatible(reqLeft, reqRight, propsLeft, propsRight));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations