|
43 | 43 | import io.trino.spi.block.BlockBuilder;
|
44 | 44 | import io.trino.spi.block.MapBlockBuilder;
|
45 | 45 | import io.trino.spi.block.RowBlockBuilder;
|
46 |
| -import io.trino.spi.block.SqlMap; |
47 | 46 | import io.trino.spi.connector.ConnectorPageSource;
|
48 | 47 | import io.trino.spi.connector.ConnectorSession;
|
49 |
| -import io.trino.spi.connector.RecordCursor; |
50 |
| -import io.trino.spi.connector.RecordPageSource; |
51 | 48 | import io.trino.spi.connector.SourcePage;
|
52 | 49 | import io.trino.spi.type.ArrayType;
|
53 | 50 | import io.trino.spi.type.CharType;
|
54 |
| -import io.trino.spi.type.DateType; |
55 | 51 | import io.trino.spi.type.DecimalType;
|
56 | 52 | import io.trino.spi.type.Decimals;
|
57 | 53 | import io.trino.spi.type.Int128;
|
|
62 | 58 | import io.trino.spi.type.SqlDecimal;
|
63 | 59 | import io.trino.spi.type.SqlTimestamp;
|
64 | 60 | import io.trino.spi.type.SqlVarbinary;
|
65 |
| -import io.trino.spi.type.TimestampType; |
66 | 61 | import io.trino.spi.type.Type;
|
67 | 62 | import io.trino.spi.type.VarcharType;
|
68 | 63 | import io.trino.testing.TestingConnectorSession;
|
|
87 | 82 | import java.io.FileOutputStream;
|
88 | 83 | import java.io.IOException;
|
89 | 84 | import java.io.UncheckedIOException;
|
90 |
| -import java.math.BigInteger; |
91 |
| -import java.util.ArrayList; |
92 |
| -import java.util.Collections; |
93 |
| -import java.util.HashMap; |
94 | 85 | import java.util.Iterator;
|
95 | 86 | import java.util.List;
|
96 | 87 | import java.util.Map;
|
|
114 | 105 | import static io.trino.plugin.hive.HiveSessionProperties.getParquetMaxReadBlockSize;
|
115 | 106 | import static io.trino.plugin.hive.HiveTestUtils.getHiveSession;
|
116 | 107 | import static io.trino.plugin.hive.parquet.ParquetUtil.createPageSource;
|
117 |
| -import static io.trino.plugin.hive.util.HiveUtil.isStructuralType; |
118 | 108 | import static io.trino.plugin.hive.util.SerdeConstants.LIST_COLUMNS;
|
119 | 109 | import static io.trino.plugin.hive.util.SerdeConstants.LIST_COLUMN_TYPES;
|
120 | 110 | import static io.trino.spi.type.BigintType.BIGINT;
|
|
131 | 121 | import static io.trino.spi.type.TinyintType.TINYINT;
|
132 | 122 | import static io.trino.spi.type.VarbinaryType.VARBINARY;
|
133 | 123 | import static io.trino.spi.type.Varchars.truncateToLength;
|
134 |
| -import static java.lang.Float.intBitsToFloat; |
135 | 124 | import static java.lang.Math.toIntExact;
|
136 |
| -import static java.nio.charset.StandardCharsets.UTF_8; |
137 | 125 | import static java.util.Arrays.stream;
|
138 | 126 | import static java.util.Collections.singletonList;
|
139 | 127 | import static java.util.Objects.requireNonNull;
|
@@ -482,12 +470,7 @@ private void assertFileContents(
|
482 | 470 | dataFile,
|
483 | 471 | columnNames,
|
484 | 472 | columnTypes)) {
|
485 |
| - if (pageSource instanceof RecordPageSource recordPageSource) { |
486 |
| - assertRecordCursor(columnTypes, expectedValues, recordPageSource.getCursor()); |
487 |
| - } |
488 |
| - else { |
489 |
| - assertPageSource(columnTypes, expectedValues, pageSource); |
490 |
| - } |
| 473 | + assertPageSource(columnTypes, expectedValues, pageSource); |
491 | 474 | assertThat(stream(expectedValues).allMatch(Iterator::hasNext)).isFalse();
|
492 | 475 | }
|
493 | 476 | }
|
@@ -520,131 +503,6 @@ private static void assertPageSource(List<Type> types, Iterator<?>[] valuesByFie
|
520 | 503 | }
|
521 | 504 | }
|
522 | 505 |
|
523 |
| - private static void assertRecordCursor(List<Type> types, Iterator<?>[] valuesByField, RecordCursor cursor) |
524 |
| - { |
525 |
| - while (cursor.advanceNextPosition()) { |
526 |
| - for (int field = 0; field < types.size(); field++) { |
527 |
| - assertThat(valuesByField[field].hasNext()).isTrue(); |
528 |
| - Object expected = valuesByField[field].next(); |
529 |
| - Object actual = getActualCursorValue(cursor, types.get(field), field); |
530 |
| - assertThat(actual).isEqualTo(expected); |
531 |
| - } |
532 |
| - } |
533 |
| - } |
534 |
| - |
535 |
| - private static Object getActualCursorValue(RecordCursor cursor, Type type, int field) |
536 |
| - { |
537 |
| - Object fieldFromCursor = getFieldFromCursor(cursor, type, field); |
538 |
| - if (fieldFromCursor == null) { |
539 |
| - return null; |
540 |
| - } |
541 |
| - if (isStructuralType(type)) { |
542 |
| - if (type instanceof ArrayType arrayType) { |
543 |
| - return toArrayValue((Block) fieldFromCursor, arrayType.getElementType()); |
544 |
| - } |
545 |
| - if (type instanceof MapType mapType) { |
546 |
| - return toMapValue((SqlMap) fieldFromCursor, mapType.getKeyType(), mapType.getValueType()); |
547 |
| - } |
548 |
| - if (type instanceof RowType) { |
549 |
| - return toRowValue((Block) fieldFromCursor, type.getTypeParameters()); |
550 |
| - } |
551 |
| - } |
552 |
| - if (type instanceof DecimalType decimalType) { |
553 |
| - return new SqlDecimal((BigInteger) fieldFromCursor, decimalType.getPrecision(), decimalType.getScale()); |
554 |
| - } |
555 |
| - if (type instanceof VarcharType) { |
556 |
| - return new String(((Slice) fieldFromCursor).getBytes(), UTF_8); |
557 |
| - } |
558 |
| - if (VARBINARY.equals(type)) { |
559 |
| - return new SqlVarbinary(((Slice) fieldFromCursor).getBytes()); |
560 |
| - } |
561 |
| - if (DATE.equals(type)) { |
562 |
| - return new SqlDate(((Long) fieldFromCursor).intValue()); |
563 |
| - } |
564 |
| - if (TIMESTAMP_MILLIS.equals(type)) { |
565 |
| - return SqlTimestamp.fromMillis(3, (long) fieldFromCursor); |
566 |
| - } |
567 |
| - return fieldFromCursor; |
568 |
| - } |
569 |
| - |
570 |
| - private static Object getFieldFromCursor(RecordCursor cursor, Type type, int field) |
571 |
| - { |
572 |
| - if (cursor.isNull(field)) { |
573 |
| - return null; |
574 |
| - } |
575 |
| - if (BOOLEAN.equals(type)) { |
576 |
| - return cursor.getBoolean(field); |
577 |
| - } |
578 |
| - if (TINYINT.equals(type)) { |
579 |
| - return cursor.getLong(field); |
580 |
| - } |
581 |
| - if (SMALLINT.equals(type)) { |
582 |
| - return cursor.getLong(field); |
583 |
| - } |
584 |
| - if (INTEGER.equals(type)) { |
585 |
| - return (int) cursor.getLong(field); |
586 |
| - } |
587 |
| - if (BIGINT.equals(type)) { |
588 |
| - return cursor.getLong(field); |
589 |
| - } |
590 |
| - if (REAL.equals(type)) { |
591 |
| - return intBitsToFloat((int) cursor.getLong(field)); |
592 |
| - } |
593 |
| - if (DOUBLE.equals(type)) { |
594 |
| - return cursor.getDouble(field); |
595 |
| - } |
596 |
| - if (type instanceof VarcharType || type instanceof CharType || VARBINARY.equals(type)) { |
597 |
| - return cursor.getSlice(field); |
598 |
| - } |
599 |
| - if (DateType.DATE.equals(type)) { |
600 |
| - return cursor.getLong(field); |
601 |
| - } |
602 |
| - if (TimestampType.TIMESTAMP_MILLIS.equals(type)) { |
603 |
| - return cursor.getLong(field); |
604 |
| - } |
605 |
| - if (isStructuralType(type)) { |
606 |
| - return cursor.getObject(field); |
607 |
| - } |
608 |
| - if (type instanceof DecimalType decimalType) { |
609 |
| - if (decimalType.isShort()) { |
610 |
| - return BigInteger.valueOf(cursor.getLong(field)); |
611 |
| - } |
612 |
| - return ((Int128) cursor.getObject(field)).toBigInteger(); |
613 |
| - } |
614 |
| - throw new RuntimeException("unknown type"); |
615 |
| - } |
616 |
| - |
617 |
| - private static Map<?, ?> toMapValue(SqlMap sqlMap, Type keyType, Type valueType) |
618 |
| - { |
619 |
| - int rawOffset = sqlMap.getRawOffset(); |
620 |
| - Block rawKeyBlock = sqlMap.getRawKeyBlock(); |
621 |
| - Block rawValueBlock = sqlMap.getRawValueBlock(); |
622 |
| - |
623 |
| - Map<Object, Object> map = new HashMap<>(sqlMap.getSize()); |
624 |
| - for (int i = 0; i < sqlMap.getSize(); i++) { |
625 |
| - map.put(keyType.getObjectValue(rawKeyBlock, rawOffset + i), valueType.getObjectValue(rawValueBlock, rawOffset + i)); |
626 |
| - } |
627 |
| - return Collections.unmodifiableMap(map); |
628 |
| - } |
629 |
| - |
630 |
| - private static List<?> toArrayValue(Block arrayBlock, Type elementType) |
631 |
| - { |
632 |
| - List<Object> values = new ArrayList<>(); |
633 |
| - for (int position = 0; position < arrayBlock.getPositionCount(); position++) { |
634 |
| - values.add(elementType.getObjectValue(arrayBlock, position)); |
635 |
| - } |
636 |
| - return Collections.unmodifiableList(values); |
637 |
| - } |
638 |
| - |
639 |
| - private static List<?> toRowValue(Block rowBlock, List<Type> fieldTypes) |
640 |
| - { |
641 |
| - List<Object> values = new ArrayList<>(rowBlock.getPositionCount()); |
642 |
| - for (int i = 0; i < rowBlock.getPositionCount(); i++) { |
643 |
| - values.add(fieldTypes.get(i).getObjectValue(rowBlock, i)); |
644 |
| - } |
645 |
| - return Collections.unmodifiableList(values); |
646 |
| - } |
647 |
| - |
648 | 506 | private static HiveConfig createHiveConfig(boolean useParquetColumnNames)
|
649 | 507 | {
|
650 | 508 | return new HiveConfig()
|
|
0 commit comments