Search in sources :

Example 6 with CaseInsensitiveStringMap

use of org.apache.spark.sql.util.CaseInsensitiveStringMap 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 7 with CaseInsensitiveStringMap

use of org.apache.spark.sql.util.CaseInsensitiveStringMap 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)

Example 8 with CaseInsensitiveStringMap

use of org.apache.spark.sql.util.CaseInsensitiveStringMap in project iceberg by apache.

the class TestFilteredScan method testUnpartitionedIDFilters.

@Test
public void testUnpartitionedIDFilters() {
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", unpartitioned.toString()));
    SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
    for (int i = 0; i < 10; i += 1) {
        pushFilters(builder, EqualTo.apply("id", i));
        Batch scan = builder.build().toBatch();
        InputPartition[] partitions = scan.planInputPartitions();
        Assert.assertEquals("Should only create one task for a small file", 1, partitions.length);
        // validate row filtering
        assertEqualsSafe(SCHEMA.asStruct(), expected(i), read(unpartitioned.toString(), vectorized, "id = " + i));
    }
}
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 9 with CaseInsensitiveStringMap

use of org.apache.spark.sql.util.CaseInsensitiveStringMap in project iceberg by apache.

the class TestFilteredScan method testPartitionedByDataStartsWithFilter.

@Test
public void testPartitionedByDataStartsWithFilter() {
    Table table = buildPartitionedTable("partitioned_by_data", PARTITION_BY_DATA, "data_ident", "data");
    CaseInsensitiveStringMap options = new CaseInsensitiveStringMap(ImmutableMap.of("path", table.location()));
    SparkScanBuilder builder = new SparkScanBuilder(spark, TABLES.load(options.get("path")), options);
    pushFilters(builder, new StringStartsWith("data", "junc"));
    Batch scan = builder.build().toBatch();
    Assert.assertEquals(1, scan.planInputPartitions().length);
}
Also used : 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 10 with CaseInsensitiveStringMap

use of org.apache.spark.sql.util.CaseInsensitiveStringMap in project iceberg by apache.

the class TestFilteredScan method testPartitionedByIdStartsWith.

@Test
public void testPartitionedByIdStartsWith() {
    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 StringStartsWith("data", "junc"));
    Batch scan = builder.build().toBatch();
    Assert.assertEquals(1, scan.planInputPartitions().length);
}
Also used : 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)

Aggregations

CaseInsensitiveStringMap (org.apache.spark.sql.util.CaseInsensitiveStringMap)14 Test (org.junit.Test)11 Batch (org.apache.spark.sql.connector.read.Batch)10 Table (org.apache.iceberg.Table)8 InputPartition (org.apache.spark.sql.connector.read.InputPartition)4 StringStartsWith (org.apache.spark.sql.sources.StringStartsWith)4 PathIdentifier (org.apache.iceberg.spark.PathIdentifier)2 Not (org.apache.spark.sql.sources.Not)2 Schema (org.apache.iceberg.Schema)1 Snapshot (org.apache.iceberg.Snapshot)1 TableScan (org.apache.iceberg.TableScan)1 Spark3Util (org.apache.iceberg.spark.Spark3Util)1 SparkCatalog (org.apache.iceberg.spark.SparkCatalog)1 SparkReadConf (org.apache.iceberg.spark.SparkReadConf)1 NoSuchTableException (org.apache.spark.sql.catalyst.analysis.NoSuchTableException)1 CatalogPlugin (org.apache.spark.sql.connector.catalog.CatalogPlugin)1 Identifier (org.apache.spark.sql.connector.catalog.Identifier)1 TableCatalog (org.apache.spark.sql.connector.catalog.TableCatalog)1 Before (org.junit.Before)1