Search in sources :

Example 1 with Batch

use of org.apache.spark.sql.connector.read.Batch in project iceberg by apache.

the class TestFilteredScan method testUnpartitionedCaseInsensitiveIDFilters.

@Test
public void testUnpartitionedCaseInsensitiveIDFilters() {
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", unpartitioned.toString()));
    // set spark.sql.caseSensitive to false
    String caseSensitivityBeforeTest = TestFilteredScan.spark.conf().get("spark.sql.caseSensitive");
    TestFilteredScan.spark.conf().set("spark.sql.caseSensitive", "false");
    try {
        for (int i = 0; i < 10; i += 1) {
            SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options).caseSensitive(false);
            // note lower(ID) == lower(id), so there must be a match
            pushFilters(builder, EqualTo.apply("ID", i));
            Batch scan = builder.build().toBatch();
            InputPartition[] tasks = scan.planInputPartitions();
            Assert.assertEquals("Should only create one task for a small file", 1, tasks.length);
            // validate row filtering
            assertEqualsSafe(SCHEMA.asStruct(), expected(i), read(unpartitioned.toString(), vectorized, "id = " + i));
        }
    } finally {
        // return global conf to previous state
        TestFilteredScan.spark.conf().set("spark.sql.caseSensitive", caseSensitivityBeforeTest);
    }
}
Also used : Batch(org.apache.spark.sql.connector.read.Batch) InputPartition(org.apache.spark.sql.connector.read.InputPartition) CaseInsensitiveStringMap(org.apache.spark.sql.util.CaseInsensitiveStringMap) Test(org.junit.Test)

Example 2 with Batch

use of org.apache.spark.sql.connector.read.Batch in project iceberg by apache.

the class TestFilteredScan method testUnpartitionedTimestampFilter.

@Test
public void testUnpartitionedTimestampFilter() {
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", unpartitioned.toString()));
    SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
    pushFilters(builder, LessThan.apply("ts", "2017-12-22T00:00:00+00:00"));
    Batch scan = builder.build().toBatch();
    InputPartition[] tasks = scan.planInputPartitions();
    Assert.assertEquals("Should only create one task for a small file", 1, tasks.length);
    assertEqualsSafe(SCHEMA.asStruct(), expected(5, 6, 7, 8, 9), read(unpartitioned.toString(), vectorized, "ts < cast('2017-12-22 00:00:00+00:00' as timestamp)"));
}
Also used : Batch(org.apache.spark.sql.connector.read.Batch) InputPartition(org.apache.spark.sql.connector.read.InputPartition) CaseInsensitiveStringMap(org.apache.spark.sql.util.CaseInsensitiveStringMap) Test(org.junit.Test)

Example 3 with Batch

use of org.apache.spark.sql.connector.read.Batch in project iceberg by apache.

the class TestFilteredScan method testBucketPartitionedIDFilters.

@Test
public void testBucketPartitionedIDFilters() {
    Table table = buildPartitionedTable("bucketed_by_id", BUCKET_BY_ID, "bucket4", "id");
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", table.location()));
    Batch unfiltered = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options).build().toBatch();
    Assert.assertEquals("Unfiltered table should created 4 read tasks", 4, unfiltered.planInputPartitions().length);
    for (int i = 0; i < 10; i += 1) {
        SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
        pushFilters(builder, EqualTo.apply("id", i));
        Batch scan = builder.build().toBatch();
        InputPartition[] tasks = scan.planInputPartitions();
        // validate predicate push-down
        Assert.assertEquals("Should create one task for a single bucket", 1, tasks.length);
        // validate row filtering
        assertEqualsSafe(SCHEMA.asStruct(), expected(i), read(table.location(), vectorized, "id = " + i));
    }
}
Also used : Table(org.apache.iceberg.Table) Batch(org.apache.spark.sql.connector.read.Batch) InputPartition(org.apache.spark.sql.connector.read.InputPartition) CaseInsensitiveStringMap(org.apache.spark.sql.util.CaseInsensitiveStringMap) Test(org.junit.Test)

Example 4 with Batch

use of org.apache.spark.sql.connector.read.Batch in project iceberg by apache.

the class TestFilteredScan method testPartitionedByIdNotStartsWith.

@Test
public void testPartitionedByIdNotStartsWith() {
    Table table = buildPartitionedTable("partitioned_by_id", PARTITION_BY_ID, "id_ident", "id");
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", table.location()));
    SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
    pushFilters(builder, new Not(new StringStartsWith("data", "junc")));
    Batch scan = builder.build().toBatch();
    Assert.assertEquals(9, scan.planInputPartitions().length);
}
Also used : Not(org.apache.spark.sql.sources.Not) Table(org.apache.iceberg.Table) StringStartsWith(org.apache.spark.sql.sources.StringStartsWith) Batch(org.apache.spark.sql.connector.read.Batch) CaseInsensitiveStringMap(org.apache.spark.sql.util.CaseInsensitiveStringMap) Test(org.junit.Test)

Example 5 with Batch

use of org.apache.spark.sql.connector.read.Batch in project iceberg by apache.

the class TestFilteredScan method testHourPartitionedTimestampFilters.

@SuppressWarnings("checkstyle:AvoidNestedBlocks")
@Test
public void testHourPartitionedTimestampFilters() {
    Table table = buildPartitionedTable("partitioned_by_hour", PARTITION_BY_HOUR, "ts_hour", "ts");
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", table.location()));
    Batch unfiltered = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options).build().toBatch();
    Assert.assertEquals("Unfiltered table should created 9 read tasks", 9, unfiltered.planInputPartitions().length);
    {
        SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
        pushFilters(builder, LessThan.apply("ts", "2017-12-22T00:00:00+00:00"));
        Batch scan = builder.build().toBatch();
        InputPartition[] tasks = scan.planInputPartitions();
        Assert.assertEquals("Should create 4 tasks for 2017-12-21: 15, 17, 21, 22", 4, tasks.length);
        assertEqualsSafe(SCHEMA.asStruct(), expected(8, 9, 7, 6, 5), read(table.location(), vectorized, "ts < cast('2017-12-22 00:00:00+00:00' as timestamp)"));
    }
    {
        SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
        pushFilters(builder, And.apply(GreaterThan.apply("ts", "2017-12-22T06:00:00+00:00"), LessThan.apply("ts", "2017-12-22T08:00:00+00:00")));
        Batch scan = builder.build().toBatch();
        InputPartition[] tasks = scan.planInputPartitions();
        Assert.assertEquals("Should create 2 tasks for 2017-12-22: 6, 7", 2, tasks.length);
        assertEqualsSafe(SCHEMA.asStruct(), expected(2, 1), read(table.location(), vectorized, "ts > cast('2017-12-22 06:00:00+00:00' as timestamp) and " + "ts < cast('2017-12-22 08:00:00+00:00' as timestamp)"));
    }
}
Also used : Table(org.apache.iceberg.Table) Batch(org.apache.spark.sql.connector.read.Batch) CaseInsensitiveStringMap(org.apache.spark.sql.util.CaseInsensitiveStringMap) Test(org.junit.Test)

Aggregations

Batch (org.apache.spark.sql.connector.read.Batch)10 CaseInsensitiveStringMap (org.apache.spark.sql.util.CaseInsensitiveStringMap)10 Test (org.junit.Test)10 Table (org.apache.iceberg.Table)7 InputPartition (org.apache.spark.sql.connector.read.InputPartition)4 StringStartsWith (org.apache.spark.sql.sources.StringStartsWith)4 Not (org.apache.spark.sql.sources.Not)2