|
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,129 @@ 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 testParquetTupleDomainStructWithPrimitiveColumnPredicate(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 testParquetTupleDomainStructWithComplexColumnPredicate(boolean useColumNames) |
| 173 | + { |
| 174 | + RowType c1Type = rowType( |
| 175 | + RowType.field("c1", INTEGER), |
| 176 | + RowType.field("c2", INTEGER)); |
| 177 | + RowType baseType = rowType( |
| 178 | + RowType.field("a", INTEGER), |
| 179 | + RowType.field("b", INTEGER), |
| 180 | + RowType.field("c", c1Type)); |
| 181 | + |
| 182 | + HiveColumnProjectionInfo columnProjectionInfo = new HiveColumnProjectionInfo( |
| 183 | + ImmutableList.of(2), |
| 184 | + ImmutableList.of("C"), |
| 185 | + HiveType.toHiveType(c1Type), |
| 186 | + c1Type); |
| 187 | + |
| 188 | + HiveColumnHandle projectedColumn = new HiveColumnHandle( |
| 189 | + "row_field", |
| 190 | + 0, |
| 191 | + HiveType.toHiveType(baseType), |
| 192 | + baseType, |
| 193 | + Optional.of(columnProjectionInfo), |
| 194 | + REGULAR, |
| 195 | + Optional.empty()); |
| 196 | + |
| 197 | + Domain predicateDomain = Domain.onlyNull(c1Type); |
| 198 | + TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(projectedColumn, predicateDomain)); |
| 199 | + |
| 200 | + MessageType fileSchema = new MessageType("hive_schema", |
| 201 | + new GroupType(OPTIONAL, "row_field", |
| 202 | + new PrimitiveType(OPTIONAL, INT32, "a"), |
| 203 | + new PrimitiveType(OPTIONAL, INT32, "b"), |
| 204 | + new GroupType(OPTIONAL, |
| 205 | + "c", |
| 206 | + new PrimitiveType(OPTIONAL, INT32, "c1"), |
| 207 | + new PrimitiveType(OPTIONAL, INT32, "c2")))); |
| 208 | + Map<List<String>, ColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema); |
| 209 | + // skip looking up predicates for complex types as Parquet only stores stats for primitives |
| 210 | + TupleDomain<ColumnDescriptor> calculatedTupleDomain = getParquetTupleDomain(descriptorsByPath, tupleDomain, fileSchema, useColumNames); |
| 211 | + assertTrue(calculatedTupleDomain.isAll()); |
| 212 | + } |
| 213 | + |
| 214 | + @Test(dataProvider = "useColumnNames") |
| 215 | + public void testParquetTupleDomainStructWithMissingPrimitiveColumn(boolean useColumnNames) |
| 216 | + { |
| 217 | + RowType baseType = rowType( |
| 218 | + RowType.field("a", INTEGER), |
| 219 | + RowType.field("b", INTEGER), |
| 220 | + RowType.field("non_exist", INTEGER)); |
| 221 | + |
| 222 | + HiveColumnProjectionInfo columnProjectionInfo = new HiveColumnProjectionInfo( |
| 223 | + ImmutableList.of(2), |
| 224 | + ImmutableList.of("non_exist"), |
| 225 | + HiveType.HIVE_INT, |
| 226 | + INTEGER); |
| 227 | + |
| 228 | + HiveColumnHandle projectedColumn = new HiveColumnHandle( |
| 229 | + "row_field", |
| 230 | + 0, |
| 231 | + HiveType.toHiveType(baseType), |
| 232 | + baseType, |
| 233 | + Optional.of(columnProjectionInfo), |
| 234 | + REGULAR, |
| 235 | + Optional.empty()); |
| 236 | + |
| 237 | + Domain predicateDomain = Domain.singleValue(INTEGER, 123L); |
| 238 | + TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(projectedColumn, predicateDomain)); |
| 239 | + |
| 240 | + MessageType fileSchema = new MessageType("hive_schema", |
| 241 | + new GroupType(OPTIONAL, "row_field", |
| 242 | + new PrimitiveType(OPTIONAL, INT32, "a"), |
| 243 | + new PrimitiveType(OPTIONAL, INT32, "b"))); |
| 244 | + Map<List<String>, ColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema); |
| 245 | + TupleDomain<ColumnDescriptor> calculatedTupleDomain = getParquetTupleDomain(descriptorsByPath, tupleDomain, fileSchema, useColumnNames); |
| 246 | + assertTrue(calculatedTupleDomain.isAll()); |
| 247 | + } |
| 248 | + |
131 | 249 | @Test(dataProvider = "useColumnNames") |
132 | 250 | public void testParquetTupleDomainMap(boolean useColumnNames) |
133 | 251 | { |
|
0 commit comments