Search in sources :

Example 1 with InvalidFunctionArgumentException

use of com.facebook.presto.common.InvalidFunctionArgumentException in project presto by prestodb.

the class TestSelectiveOrcReader method testArrayIndexOutOfBounds.

@Test
public void testArrayIndexOutOfBounds() throws Exception {
    Random random = new Random(0);
    // non-null arrays of varying sizes
    try {
        tester.testRoundTrip(arrayType(INTEGER), createList(NUM_ROWS, i -> randomIntegers(random.nextInt(10), random)), ImmutableList.of(ImmutableMap.of(new Subfield("c[2]"), IS_NULL)));
        fail("Expected 'Array subscript out of bounds' exception");
    } catch (InvalidFunctionArgumentException e) {
        assertTrue(e.getMessage().contains("Array subscript out of bounds"));
    }
    // non-null nested arrays of varying sizes
    try {
        tester.testRoundTrip(arrayType(arrayType(INTEGER)), createList(NUM_ROWS, i -> ImmutableList.of(randomIntegers(random.nextInt(5), random), randomIntegers(random.nextInt(5), random))), ImmutableList.of(ImmutableMap.of(new Subfield("c[2][3]"), IS_NULL)));
        fail("Expected 'Array subscript out of bounds' exception");
    } catch (InvalidFunctionArgumentException e) {
        assertTrue(e.getMessage().contains("Array subscript out of bounds"));
    }
    // empty arrays
    try {
        tester.testRoundTrip(arrayType(INTEGER), nCopies(NUM_ROWS, ImmutableList.of()), ImmutableList.of(ImmutableMap.of(new Subfield("c[2]"), IS_NULL)));
        fail("Expected 'Array subscript out of bounds' exception");
    } catch (InvalidFunctionArgumentException e) {
        assertTrue(e.getMessage().contains("Array subscript out of bounds"));
    }
    // empty nested arrays
    try {
        tester.testRoundTrip(arrayType(arrayType(INTEGER)), nCopies(NUM_ROWS, ImmutableList.of()), ImmutableList.of(ImmutableMap.of(new Subfield("c[2][3]"), IS_NULL)));
        fail("Expected 'Array subscript out of bounds' exception");
    } catch (InvalidFunctionArgumentException e) {
        assertTrue(e.getMessage().contains("Array subscript out of bounds"));
    }
}
Also used : CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) Page(com.facebook.presto.common.Page) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Test(org.testng.annotations.Test) Random(java.util.Random) OrcTester.quickSelectiveOrcTester(com.facebook.presto.orc.OrcTester.quickSelectiveOrcTester) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Iterables.concat(com.google.common.collect.Iterables.concat) Iterables.cycle(com.google.common.collect.Iterables.cycle) Slices(io.airlift.slice.Slices) Map(java.util.Map) HIVE_STORAGE_TIME_ZONE(com.facebook.presto.orc.OrcTester.HIVE_STORAGE_TIME_ZONE) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BigInteger(java.math.BigInteger) SqlDecimal(com.facebook.presto.common.type.SqlDecimal) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) NONE(com.facebook.presto.orc.metadata.CompressionKind.NONE) Collections.nCopies(java.util.Collections.nCopies) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Range(com.google.common.collect.Range) BooleanValue(com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue) Iterables.limit(com.google.common.collect.Iterables.limit) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) Assertions.assertBetweenInclusive(com.facebook.airlift.testing.Assertions.assertBetweenInclusive) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) CompressionKind(com.facebook.presto.orc.metadata.CompressionKind) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) IntStream(java.util.stream.IntStream) MAX_BLOCK_SIZE(com.facebook.presto.orc.OrcTester.MAX_BLOCK_SIZE) DecimalType(com.facebook.presto.common.type.DecimalType) ContiguousSet(com.google.common.collect.ContiguousSet) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) DateTimeTestingUtils.sqlTimestampOf(com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf) Assert.assertEquals(org.testng.Assert.assertEquals) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Function(java.util.function.Function) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ZLIB(com.facebook.presto.orc.metadata.CompressionKind.ZLIB) SqlDate(com.facebook.presto.common.type.SqlDate) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) DiscreteDomain(com.google.common.collect.DiscreteDomain) OrcTester.writeOrcColumnsPresto(com.facebook.presto.orc.OrcTester.writeOrcColumnsPresto) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) MAX_BATCH_SIZE(com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) InvalidFunctionArgumentException(com.facebook.presto.common.InvalidFunctionArgumentException) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) AbstractIterator(com.google.common.collect.AbstractIterator) TupleDomainFilterUtils.toBigintValues(com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) DWRF(com.facebook.presto.orc.OrcTester.Format.DWRF) OrcReaderSettings(com.facebook.presto.orc.OrcTester.OrcReaderSettings) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) BytesValues(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) Collections(java.util.Collections) ZSTD(com.facebook.presto.orc.metadata.CompressionKind.ZSTD) InvalidFunctionArgumentException(com.facebook.presto.common.InvalidFunctionArgumentException) Random(java.util.Random) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Aggregations

Assertions.assertBetweenInclusive (com.facebook.airlift.testing.Assertions.assertBetweenInclusive)1 InvalidFunctionArgumentException (com.facebook.presto.common.InvalidFunctionArgumentException)1 Page (com.facebook.presto.common.Page)1 Subfield (com.facebook.presto.common.Subfield)1 Block (com.facebook.presto.common.block.Block)1 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)1 BigintRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange)1 BigintValuesUsingHashTable (com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable)1 BooleanValue (com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue)1 BytesRange (com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange)1 BytesValues (com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues)1 DoubleRange (com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange)1 FloatRange (com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange)1 IS_NOT_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL)1 IS_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL)1 TupleDomainFilterUtils.toBigintValues (com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 CharType (com.facebook.presto.common.type.CharType)1 CharType.createCharType (com.facebook.presto.common.type.CharType.createCharType)1