|
17 | 17 | import com.google.common.collect.ImmutableMap; |
18 | 18 | import com.google.common.collect.Iterables; |
19 | 19 | import io.trino.plugin.hive.HiveColumnHandle; |
| 20 | +import io.trino.plugin.hive.HiveColumnProjectionInfo; |
20 | 21 | import io.trino.plugin.hive.HiveType; |
21 | 22 | import io.trino.spi.predicate.Domain; |
22 | 23 | import io.trino.spi.predicate.TupleDomain; |
@@ -122,12 +123,86 @@ public void testParquetTupleDomainStruct(boolean useColumnNames) |
122 | 123 | MessageType fileSchema = new MessageType("hive_schema", |
123 | 124 | new GroupType(OPTIONAL, "my_struct", |
124 | 125 | new PrimitiveType(OPTIONAL, INT32, "a"), |
125 | | - new PrimitiveType(OPTIONAL, INT32, "b"))); |
| 126 | + new PrimitiveType(OPTIONAL, INT32, "b"), |
| 127 | + new PrimitiveType(OPTIONAL, INT32, "c"))); |
126 | 128 | Map<List<String>, ColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema); |
127 | 129 | TupleDomain<ColumnDescriptor> tupleDomain = getParquetTupleDomain(descriptorsByPath, domain, fileSchema, useColumnNames); |
128 | 130 | assertTrue(tupleDomain.isAll()); |
129 | 131 | } |
130 | 132 |
|
| 133 | + @Test(dataProvider = "useColumnNames") |
| 134 | + public void testParquetTupleDomainStructNestedColumn(boolean useColumNames) |
| 135 | + { |
| 136 | + RowType baseType = rowType( |
| 137 | + RowType.field("a", INTEGER), |
| 138 | + RowType.field("b", INTEGER), |
| 139 | + RowType.field("c", INTEGER)); |
| 140 | + |
| 141 | + HiveColumnProjectionInfo columnProjectionInfo = new HiveColumnProjectionInfo( |
| 142 | + ImmutableList.of(1), |
| 143 | + ImmutableList.of("b"), |
| 144 | + HiveType.HIVE_INT, |
| 145 | + INTEGER); |
| 146 | + |
| 147 | + HiveColumnHandle projectedColumn = new HiveColumnHandle( |
| 148 | + "row_field", |
| 149 | + 0, |
| 150 | + HiveType.toHiveType(baseType), |
| 151 | + baseType, |
| 152 | + Optional.of(columnProjectionInfo), |
| 153 | + REGULAR, |
| 154 | + Optional.empty()); |
| 155 | + |
| 156 | + Domain predicateDomain = Domain.singleValue(INTEGER, 123L); |
| 157 | + TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(projectedColumn, predicateDomain)); |
| 158 | + |
| 159 | + MessageType fileSchema = new MessageType("hive_schema", |
| 160 | + new GroupType(OPTIONAL, "row_field", |
| 161 | + new PrimitiveType(OPTIONAL, INT32, "a"), |
| 162 | + new PrimitiveType(OPTIONAL, INT32, "b"), |
| 163 | + new PrimitiveType(OPTIONAL, INT32, "c"))); |
| 164 | + Map<List<String>, ColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema); |
| 165 | + TupleDomain<ColumnDescriptor> calculatedTupleDomain = getParquetTupleDomain(descriptorsByPath, tupleDomain, fileSchema, useColumNames); |
| 166 | + assertEquals(calculatedTupleDomain.getDomains().get().size(), 1); |
| 167 | + ColumnDescriptor selectedColumnDescriptor = descriptorsByPath.get(ImmutableList.of("row_field", "b")); |
| 168 | + assertEquals(calculatedTupleDomain.getDomains().get().get(selectedColumnDescriptor), (predicateDomain)); |
| 169 | + } |
| 170 | + |
| 171 | + @Test(dataProvider = "useColumnNames") |
| 172 | + public void testParquetTupleDomainStructNestedColumnNonExist(boolean useColumnNames) |
| 173 | + { |
| 174 | + RowType baseType = rowType( |
| 175 | + RowType.field("a", INTEGER), |
| 176 | + RowType.field("b", INTEGER), |
| 177 | + RowType.field("non_exist", INTEGER)); |
| 178 | + |
| 179 | + HiveColumnProjectionInfo columnProjectionInfo = new HiveColumnProjectionInfo( |
| 180 | + ImmutableList.of(2), |
| 181 | + ImmutableList.of("non_exist"), |
| 182 | + HiveType.HIVE_INT, |
| 183 | + INTEGER); |
| 184 | + |
| 185 | + HiveColumnHandle projectedColumn = new HiveColumnHandle( |
| 186 | + "row_field", |
| 187 | + 0, |
| 188 | + HiveType.toHiveType(baseType), |
| 189 | + baseType, |
| 190 | + Optional.of(columnProjectionInfo), |
| 191 | + REGULAR, |
| 192 | + Optional.empty()); |
| 193 | + |
| 194 | + Domain predicateDomain = Domain.singleValue(INTEGER, 123L); |
| 195 | + TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(projectedColumn, predicateDomain)); |
| 196 | + |
| 197 | + MessageType fileSchema = new MessageType("hive_schema", |
| 198 | + new GroupType(OPTIONAL, "row_field", |
| 199 | + new PrimitiveType(OPTIONAL, INT32, "a"), |
| 200 | + new PrimitiveType(OPTIONAL, INT32, "b"))); |
| 201 | + Map<List<String>, ColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema); |
| 202 | + TupleDomain<ColumnDescriptor> calculatedTupleDomain = getParquetTupleDomain(descriptorsByPath, tupleDomain, fileSchema, useColumnNames); |
| 203 | + assertTrue(calculatedTupleDomain.isAll()); |
| 204 | + } |
| 205 | + |
131 | 206 | @Test(dataProvider = "useColumnNames") |
132 | 207 | public void testParquetTupleDomainMap(boolean useColumnNames) |
133 | 208 | { |
|
0 commit comments