Search in sources :

Example 1 with MapColumnChecksum

use of com.facebook.presto.verifier.checksum.MapColumnChecksum in project presto by prestodb.

the class TestStructuredColumnMismatchResolver method testResolveMap.

@Test
public void testResolveMap() {
    MapColumnChecksum checksum1 = new MapColumnChecksum(binary(0x1), binary(0xa), binary(0xa), binary(0xc), 1);
    MapColumnChecksum checksum2 = new MapColumnChecksum(binary(0x2), binary(0xa), binary(0xb), binary(0xc), 1);
    MapColumnChecksum checksum3 = new MapColumnChecksum(binary(0x3), binary(0xb), binary(0xa), binary(0xc), 1);
    MapColumnChecksum checksum4 = new MapColumnChecksum(binary(0x4), binary(0xb), binary(0xb), binary(0xc), 1);
    MapColumnChecksum checksum5 = new MapColumnChecksum(binary(0x5), binary(0xb), binary(0xb), binary(0x1c), 1);
    MapColumnChecksum checksum6 = new MapColumnChecksum(binary(0x5), binary(0xb), binary(0xb), binary(0xc), 2);
    // resolved
    assertResolved(createMismatchedColumn(mapType(REAL, DOUBLE), checksum1, checksum4));
    assertResolved(createMismatchedColumn(mapType(new ArrayType(REAL), RowType.anonymous(ImmutableList.of(INTEGER, DOUBLE))), checksum1, checksum4));
    // not resolved, contains no floating point types
    assertNotResolved(createMismatchedColumn(mapType(new ArrayType(VARCHAR), RowType.anonymous(ImmutableList.of(INTEGER, VARCHAR))), checksum1, checksum4));
    // not resolved, cardinality mismatches
    assertNotResolved(createMismatchedColumn(mapType(DOUBLE, DOUBLE), checksum1, checksum5));
    assertNotResolved(createMismatchedColumn(mapType(DOUBLE, DOUBLE), checksum1, checksum6));
    // Key/value checks
    assertResolved(createMismatchedColumn(mapType(DOUBLE, INTEGER), checksum1, checksum3));
    assertNotResolved(createMismatchedColumn(mapType(DOUBLE, INTEGER), checksum1, checksum4));
    assertResolved(createMismatchedColumn(mapType(INTEGER, DOUBLE), checksum1, checksum2));
    assertNotResolved(createMismatchedColumn(mapType(INTEGER, DOUBLE), checksum1, checksum4));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapColumnChecksum(com.facebook.presto.verifier.checksum.MapColumnChecksum) Test(org.testng.annotations.Test)

Example 2 with MapColumnChecksum

use of com.facebook.presto.verifier.checksum.MapColumnChecksum in project presto by prestodb.

the class TestStructuredColumnMismatchResolver method testMixed.

@Test
public void testMixed() {
    ColumnMatchResult<?> resolvable1 = createMismatchedColumn(new ArrayType(new ArrayType(DOUBLE)), new ArrayColumnChecksum(binary(0xa), binary(0xc), 1), new ArrayColumnChecksum(binary(0xb), binary(0xc), 1));
    ColumnMatchResult<?> resolvable2 = createMismatchedColumn(mapType(REAL, DOUBLE), new MapColumnChecksum(binary(0x1), binary(0xa), binary(0xa), binary(0xc), 1), new MapColumnChecksum(binary(0x4), binary(0xb), binary(0xb), binary(0xc), 1));
    ColumnMatchResult<?> nonResolvable = createMismatchedColumn(VARCHAR, new SimpleColumnChecksum(binary(0xa)), new SimpleColumnChecksum(binary(0xb)));
    assertResolved(resolvable1, resolvable2);
    assertNotResolved(resolvable1, nonResolvable);
    assertNotResolved(nonResolvable, resolvable2);
    assertNotResolved(resolvable1, nonResolvable, resolvable2);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) SimpleColumnChecksum(com.facebook.presto.verifier.checksum.SimpleColumnChecksum) MapColumnChecksum(com.facebook.presto.verifier.checksum.MapColumnChecksum) ArrayColumnChecksum(com.facebook.presto.verifier.checksum.ArrayColumnChecksum) Test(org.testng.annotations.Test)

Example 3 with MapColumnChecksum

use of com.facebook.presto.verifier.checksum.MapColumnChecksum in project presto by prestodb.

the class StructuredColumnMismatchResolver method resolveResultMismatch.

@Override
public Optional<String> resolveResultMismatch(DataMatchResult matchResult, QueryBundle control) {
    checkArgument(!matchResult.isMatched(), "Expect not matched");
    if (matchResult.getMatchType() != COLUMN_MISMATCH) {
        return Optional.empty();
    }
    for (ColumnMatchResult<?> mismatchedColumn : matchResult.getMismatchedColumns()) {
        Type columnType = mismatchedColumn.getColumn().getType();
        if (columnType instanceof ArrayType) {
            ArrayColumnChecksum controlChecksum = (ArrayColumnChecksum) mismatchedColumn.getControlChecksum();
            ArrayColumnChecksum testChecksum = (ArrayColumnChecksum) mismatchedColumn.getTestChecksum();
            if (!containsFloatingPointType(((ArrayType) columnType).getElementType()) || !isCardinalityMatched(controlChecksum, testChecksum)) {
                return Optional.empty();
            }
        } else if (columnType instanceof MapType) {
            MapColumnChecksum controlChecksum = (MapColumnChecksum) mismatchedColumn.getControlChecksum();
            MapColumnChecksum testChecksum = (MapColumnChecksum) mismatchedColumn.getTestChecksum();
            if (!isCardinalityMatched(controlChecksum, testChecksum)) {
                return Optional.empty();
            }
            boolean keyContainsFloatingPoint = containsFloatingPointType(((MapType) columnType).getKeyType());
            boolean valueContainsFloatingPoint = containsFloatingPointType(((MapType) columnType).getValueType());
            if (!keyContainsFloatingPoint && !valueContainsFloatingPoint) {
                return Optional.empty();
            }
            if (!keyContainsFloatingPoint && !Objects.equals(controlChecksum.getKeysChecksum(), testChecksum.getKeysChecksum())) {
                return Optional.empty();
            }
            if (!valueContainsFloatingPoint && !Objects.equals(controlChecksum.getValuesChecksum(), testChecksum.getValuesChecksum())) {
                return Optional.empty();
            }
        } else {
            return Optional.empty();
        }
    }
    return Optional.of("Structured columns auto-resolved");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) RealType(com.facebook.presto.common.type.RealType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) DoubleType(com.facebook.presto.common.type.DoubleType) RowType(com.facebook.presto.common.type.RowType) MapColumnChecksum(com.facebook.presto.verifier.checksum.MapColumnChecksum) ArrayColumnChecksum(com.facebook.presto.verifier.checksum.ArrayColumnChecksum) MapType(com.facebook.presto.common.type.MapType)

Aggregations

ArrayType (com.facebook.presto.common.type.ArrayType)3 MapColumnChecksum (com.facebook.presto.verifier.checksum.MapColumnChecksum)3 ArrayColumnChecksum (com.facebook.presto.verifier.checksum.ArrayColumnChecksum)2 Test (org.testng.annotations.Test)2 DoubleType (com.facebook.presto.common.type.DoubleType)1 MapType (com.facebook.presto.common.type.MapType)1 RealType (com.facebook.presto.common.type.RealType)1 RowType (com.facebook.presto.common.type.RowType)1 Type (com.facebook.presto.common.type.Type)1 SimpleColumnChecksum (com.facebook.presto.verifier.checksum.SimpleColumnChecksum)1