Search in sources :

Example 26 with Schema

use of org.apache.iceberg.Schema in project hive by apache.

the class TestHiveIcebergStorageHandlerLocalScan method testMapOfMapsInTable.

@Test
public void testMapOfMapsInTable() throws IOException {
    Schema schema = new Schema(required(1, "mapofmaps", Types.MapType.ofRequired(2, 3, Types.StringType.get(), Types.MapType.ofRequired(4, 5, Types.StringType.get(), Types.StringType.get()))));
    List<Record> records = testTables.createTableWithGeneratedRecords(shell, "maptable", schema, fileFormat, 1);
    // access a single element from a map in a map
    for (int i = 0; i < records.size(); i++) {
        Map<?, ?> expectedMap = (Map<?, ?>) records.get(i).getField("mapofmaps");
        for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
            Map<?, ?> expectedInnerMap = (Map<?, ?>) entry.getValue();
            for (Map.Entry<?, ?> innerEntry : expectedInnerMap.entrySet()) {
                List<Object[]> queryResult = shell.executeStatement(String.format("SELECT mapofmaps[\"%s\"]" + "[\"%s\"] FROM maptable LIMIT 1 OFFSET %d", entry.getKey(), innerEntry.getKey(), i));
                Assert.assertEquals(innerEntry.getValue(), queryResult.get(0)[0]);
            }
        }
    }
}
Also used : Schema(org.apache.iceberg.Schema) GenericRecord(org.apache.iceberg.data.GenericRecord) Record(org.apache.iceberg.data.Record) ImmutableMap(org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 27 with Schema

use of org.apache.iceberg.Schema in project hive by apache.

the class TestHiveIcebergStorageHandlerLocalScan method testArrayOfPrimitivesInTable.

@Test
public void testArrayOfPrimitivesInTable() throws IOException {
    Schema schema = new Schema(required(1, "arrayofprimitives", Types.ListType.ofRequired(2, Types.IntegerType.get())));
    List<Record> records = testTables.createTableWithGeneratedRecords(shell, "arraytable", schema, fileFormat, 1);
    // access a single element from the array
    for (int i = 0; i < records.size(); i++) {
        List<?> expectedList = (List<?>) records.get(i).getField("arrayofprimitives");
        for (int j = 0; j < expectedList.size(); j++) {
            List<Object[]> queryResult = shell.executeStatement(String.format("SELECT arrayofprimitives[%d] FROM default.arraytable " + "LIMIT 1 OFFSET %d", j, i));
            Assert.assertEquals(expectedList.get(j), queryResult.get(0)[0]);
        }
    }
}
Also used : Schema(org.apache.iceberg.Schema) GenericRecord(org.apache.iceberg.data.GenericRecord) Record(org.apache.iceberg.data.Record) ArrayList(java.util.ArrayList) ImmutableList(org.apache.iceberg.relocated.com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 28 with Schema

use of org.apache.iceberg.Schema in project hive by apache.

the class TestHiveIcebergStorageHandlerTimezone method testDateQuery.

@Test
public void testDateQuery() throws IOException {
    Schema dateSchema = new Schema(optional(1, "d_date", Types.DateType.get()));
    List<Record> records = TestHelper.RecordsBuilder.newInstance(dateSchema).add(LocalDate.of(2020, 1, 21)).add(LocalDate.of(2020, 1, 24)).build();
    testTables.createTable(shell, "date_test", dateSchema, FileFormat.PARQUET, records);
    List<Object[]> result = shell.executeStatement("SELECT * from date_test WHERE d_date='2020-01-21'");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2020-01-21", result.get(0)[0]);
    result = shell.executeStatement("SELECT * from date_test WHERE d_date in ('2020-01-21', '2020-01-22')");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2020-01-21", result.get(0)[0]);
    result = shell.executeStatement("SELECT * from date_test WHERE d_date > '2020-01-21'");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2020-01-24", result.get(0)[0]);
    result = shell.executeStatement("SELECT * from date_test WHERE d_date='2020-01-20'");
    Assert.assertEquals(0, result.size());
}
Also used : Schema(org.apache.iceberg.Schema) Record(org.apache.iceberg.data.Record) Test(org.junit.Test)

Example 29 with Schema

use of org.apache.iceberg.Schema in project hive by apache.

the class TestHiveIcebergStorageHandlerTimezone method testTimestampQuery.

@Test
public void testTimestampQuery() throws IOException {
    Schema timestampSchema = new Schema(optional(1, "d_ts", Types.TimestampType.withoutZone()));
    List<Record> records = TestHelper.RecordsBuilder.newInstance(timestampSchema).add(LocalDateTime.of(2019, 1, 22, 9, 44, 54, 100000000)).add(LocalDateTime.of(2019, 2, 22, 9, 44, 54, 200000000)).build();
    testTables.createTable(shell, "ts_test", timestampSchema, FileFormat.PARQUET, records);
    List<Object[]> result = shell.executeStatement("SELECT d_ts FROM ts_test WHERE d_ts='2019-02-22 09:44:54.2'");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2019-02-22 09:44:54.2", result.get(0)[0]);
    result = shell.executeStatement("SELECT * FROM ts_test WHERE d_ts in ('2017-01-01 22:30:57.1', '2019-02-22 09:44:54.2')");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2019-02-22 09:44:54.2", result.get(0)[0]);
    result = shell.executeStatement("SELECT d_ts FROM ts_test WHERE d_ts < '2019-02-22 09:44:54.2'");
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("2019-01-22 09:44:54.1", result.get(0)[0]);
    result = shell.executeStatement("SELECT * FROM ts_test WHERE d_ts='2017-01-01 22:30:57.3'");
    Assert.assertEquals(0, result.size());
}
Also used : Schema(org.apache.iceberg.Schema) Record(org.apache.iceberg.data.Record) Test(org.junit.Test)

Example 30 with Schema

use of org.apache.iceberg.Schema in project hive by apache.

the class TestHiveIcebergTypes method testStructOfPrimitivesInTable.

@Test
public void testStructOfPrimitivesInTable() throws IOException {
    Schema schema = new Schema(required(1, "structofprimitives", Types.StructType.of(required(2, "key", Types.StringType.get()), required(3, "value", Types.IntegerType.get()))));
    List<Record> records = testTables.createTableWithGeneratedRecords(shell, "structtable", schema, fileFormat, 1);
    // access a single value in a struct
    for (int i = 0; i < records.size(); i++) {
        GenericRecord expectedStruct = (GenericRecord) records.get(i).getField("structofprimitives");
        List<Object[]> queryResult = shell.executeStatement(String.format("SELECT structofprimitives.key, structofprimitives.value FROM default.structtable LIMIT 1 OFFSET %d", i));
        Assert.assertEquals(expectedStruct.getField("key"), queryResult.get(0)[0]);
        Assert.assertEquals(expectedStruct.getField("value"), queryResult.get(0)[1]);
    }
}
Also used : Schema(org.apache.iceberg.Schema) Record(org.apache.iceberg.data.Record) GenericRecord(org.apache.iceberg.data.GenericRecord) GenericRecord(org.apache.iceberg.data.GenericRecord) Test(org.junit.Test)

Aggregations

Schema (org.apache.iceberg.Schema)126 Test (org.junit.Test)93 Record (org.apache.iceberg.data.Record)68 Table (org.apache.iceberg.Table)55 PartitionSpec (org.apache.iceberg.PartitionSpec)39 GenericRecord (org.apache.iceberg.data.GenericRecord)36 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)30 List (java.util.List)21 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)20 IOException (java.io.IOException)16 Types (org.apache.iceberg.types.Types)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 HashMap (java.util.HashMap)13 FileFormat (org.apache.iceberg.FileFormat)13 UpdateSchema (org.apache.iceberg.UpdateSchema)12 Path (org.apache.hadoop.fs.Path)11 Collectors (java.util.stream.Collectors)10 ImmutableList (org.apache.iceberg.relocated.com.google.common.collect.ImmutableList)10 TestHelper (org.apache.iceberg.mr.TestHelper)9