Search in sources :

Example 1 with HiveTimestampPrecision

use of io.trino.plugin.hive.HiveTimestampPrecision in project trino by trinodb.

the class RcFilePageSourceFactory method createPageSource.

@Override
public Optional<ReaderPageSource> createPageSource(Configuration configuration, ConnectorSession session, Path path, long start, long length, long estimatedFileSize, Properties schema, List<HiveColumnHandle> columns, TupleDomain<HiveColumnHandle> effectivePredicate, Optional<AcidInfo> acidInfo, OptionalInt bucketNumber, boolean originalFile, AcidTransaction transaction) {
    RcFileEncoding rcFileEncoding;
    String deserializerClassName = getDeserializerClassName(schema);
    if (deserializerClassName.equals(LazyBinaryColumnarSerDe.class.getName())) {
        rcFileEncoding = new BinaryRcFileEncoding(timeZone);
    } else if (deserializerClassName.equals(ColumnarSerDe.class.getName())) {
        rcFileEncoding = createTextVectorEncoding(schema);
    } else {
        return Optional.empty();
    }
    checkArgument(acidInfo.isEmpty(), "Acid is not supported");
    List<HiveColumnHandle> projectedReaderColumns = columns;
    Optional<ReaderColumns> readerProjections = projectBaseColumns(columns);
    if (readerProjections.isPresent()) {
        projectedReaderColumns = readerProjections.get().get().stream().map(HiveColumnHandle.class::cast).collect(toImmutableList());
    }
    RcFileDataSource dataSource;
    try {
        FileSystem fileSystem = hdfsEnvironment.getFileSystem(session.getIdentity(), path, configuration);
        FSDataInputStream inputStream = hdfsEnvironment.doAs(session.getIdentity(), () -> fileSystem.open(path));
        if (estimatedFileSize < BUFFER_SIZE.toBytes()) {
            // Handle potentially imprecise file lengths by reading the footer
            try {
                FSDataInputStreamTail fileTail = FSDataInputStreamTail.readTail(path.toString(), estimatedFileSize, inputStream, toIntExact(BUFFER_SIZE.toBytes()));
                dataSource = new MemoryRcFileDataSource(new RcFileDataSourceId(path.toString()), fileTail.getTailSlice());
            } finally {
                inputStream.close();
            }
        } else {
            long fileSize = hdfsEnvironment.doAs(session.getIdentity(), () -> fileSystem.getFileStatus(path).getLen());
            dataSource = new HdfsRcFileDataSource(path.toString(), inputStream, fileSize, stats);
        }
    } catch (Exception e) {
        if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") || e instanceof FileNotFoundException) {
            throw new TrinoException(HIVE_CANNOT_OPEN_SPLIT, e);
        }
        throw new TrinoException(HIVE_CANNOT_OPEN_SPLIT, splitError(e, path, start, length), e);
    }
    length = min(dataSource.getSize() - start, length);
    // Split may be empty now that the correct file size is known
    if (length <= 0) {
        return Optional.of(noProjectionAdaptation(new EmptyPageSource()));
    }
    try {
        ImmutableMap.Builder<Integer, Type> readColumns = ImmutableMap.builder();
        HiveTimestampPrecision timestampPrecision = getTimestampPrecision(session);
        for (HiveColumnHandle column : projectedReaderColumns) {
            readColumns.put(column.getBaseHiveColumnIndex(), column.getHiveType().getType(typeManager, timestampPrecision));
        }
        RcFileReader rcFileReader = new RcFileReader(dataSource, rcFileEncoding, readColumns.buildOrThrow(), new AircompressorCodecFactory(new HadoopCodecFactory(configuration.getClassLoader())), start, length, BUFFER_SIZE);
        ConnectorPageSource pageSource = new RcFilePageSource(rcFileReader, projectedReaderColumns);
        return Optional.of(new ReaderPageSource(pageSource, readerProjections));
    } catch (Throwable e) {
        try {
            dataSource.close();
        } catch (IOException ignored) {
        }
        if (e instanceof TrinoException) {
            throw (TrinoException) e;
        }
        String message = splitError(e, path, start, length);
        if (e instanceof RcFileCorruptionException) {
            throw new TrinoException(HIVE_BAD_DATA, message, e);
        }
        if (e instanceof BlockMissingException) {
            throw new TrinoException(HIVE_MISSING_DATA, message, e);
        }
        throw new TrinoException(HIVE_CANNOT_OPEN_SPLIT, message, e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) BinaryRcFileEncoding(io.trino.rcfile.binary.BinaryRcFileEncoding) TextRcFileEncoding(io.trino.rcfile.text.TextRcFileEncoding) RcFileEncoding(io.trino.rcfile.RcFileEncoding) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) RcFileCorruptionException(io.trino.rcfile.RcFileCorruptionException) EmptyPageSource(io.trino.spi.connector.EmptyPageSource) FileSystem(org.apache.hadoop.fs.FileSystem) LazyBinaryColumnarSerDe(org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe) BlockMissingException(org.apache.hadoop.hdfs.BlockMissingException) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) RcFileDataSourceId(io.trino.rcfile.RcFileDataSourceId) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) IOException(java.io.IOException) FSDataInputStreamTail(io.trino.plugin.hive.util.FSDataInputStreamTail) RcFileReader(io.trino.rcfile.RcFileReader) BlockMissingException(org.apache.hadoop.hdfs.BlockMissingException) TrinoException(io.trino.spi.TrinoException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RcFileCorruptionException(io.trino.rcfile.RcFileCorruptionException) ImmutableMap(com.google.common.collect.ImmutableMap) Type(io.trino.spi.type.Type) MemoryRcFileDataSource(io.trino.rcfile.MemoryRcFileDataSource) HadoopCodecFactory(io.trino.rcfile.HadoopCodecFactory) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) TrinoException(io.trino.spi.TrinoException) ReaderPageSource(io.trino.plugin.hive.ReaderPageSource) ReaderColumns(io.trino.plugin.hive.ReaderColumns) BinaryRcFileEncoding(io.trino.rcfile.binary.BinaryRcFileEncoding) AircompressorCodecFactory(io.trino.rcfile.AircompressorCodecFactory) RcFileDataSource(io.trino.rcfile.RcFileDataSource) MemoryRcFileDataSource(io.trino.rcfile.MemoryRcFileDataSource)

Example 2 with HiveTimestampPrecision

use of io.trino.plugin.hive.HiveTimestampPrecision in project trino by trinodb.

the class HiveTypeTranslator method toTypeSignature.

public static TypeSignature toTypeSignature(TypeInfo typeInfo, HiveTimestampPrecision timestampPrecision) {
    switch(typeInfo.getCategory()) {
        case PRIMITIVE:
            Type primitiveType = fromPrimitiveType((PrimitiveTypeInfo) typeInfo, timestampPrecision);
            if (primitiveType == null) {
                break;
            }
            return primitiveType.getTypeSignature();
        case MAP:
            MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
            return mapType(toTypeSignature(mapTypeInfo.getMapKeyTypeInfo(), timestampPrecision), toTypeSignature(mapTypeInfo.getMapValueTypeInfo(), timestampPrecision));
        case LIST:
            ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
            TypeSignature elementType = toTypeSignature(listTypeInfo.getListElementTypeInfo(), timestampPrecision);
            return arrayType(typeParameter(elementType));
        case STRUCT:
            StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
            List<TypeInfo> fieldTypes = structTypeInfo.getAllStructFieldTypeInfos();
            List<String> fieldNames = structTypeInfo.getAllStructFieldNames();
            if (fieldTypes.size() != fieldNames.size()) {
                throw new TrinoException(HiveErrorCode.HIVE_INVALID_METADATA, format("Invalid Hive struct type: %s", typeInfo));
            }
            return rowType(Streams.zip(// TODO: This is a hack. Trino engine should be able to handle identifiers in a case insensitive way where necessary.
            fieldNames.stream().map(s -> s.toLowerCase(Locale.US)), fieldTypes.stream().map(type -> toTypeSignature(type, timestampPrecision)), TypeSignatureParameter::namedField).collect(Collectors.toList()));
        case UNION:
            // Use a row type to represent a union type in Hive for reading
            UnionTypeInfo unionTypeInfo = (UnionTypeInfo) typeInfo;
            List<TypeInfo> unionObjectTypes = unionTypeInfo.getAllUnionObjectTypeInfos();
            ImmutableList.Builder<TypeSignatureParameter> typeSignatures = ImmutableList.builder();
            typeSignatures.add(namedField("tag", TINYINT.getTypeSignature()));
            for (int i = 0; i < unionObjectTypes.size(); i++) {
                TypeInfo unionObjectType = unionObjectTypes.get(i);
                typeSignatures.add(namedField("field" + i, toTypeSignature(unionObjectType, timestampPrecision)));
            }
            return rowType(typeSignatures.build());
    }
    throw new TrinoException(NOT_SUPPORTED, format("Unsupported Hive type: %s", typeInfo));
}
Also used : NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) HiveUtil.isMapType(io.trino.plugin.hive.util.HiveUtil.isMapType) TypeInfoFactory.getMapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getMapTypeInfo) HIVE_BYTE(io.trino.plugin.hive.HiveType.HIVE_BYTE) CharType.createCharType(io.trino.spi.type.CharType.createCharType) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) HIVE_FLOAT(io.trino.plugin.hive.HiveType.HIVE_FLOAT) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) Locale(java.util.Locale) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) INTEGER(io.trino.spi.type.IntegerType.INTEGER) SMALLINT(io.trino.spi.type.SmallintType.SMALLINT) TypeSignature(io.trino.spi.type.TypeSignature) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoException(io.trino.spi.TrinoException) HIVE_DATE(io.trino.plugin.hive.HiveType.HIVE_DATE) Streams(com.google.common.collect.Streams) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) BIGINT(io.trino.spi.type.BigintType.BIGINT) HiveErrorCode(io.trino.plugin.hive.HiveErrorCode) TypeInfoFactory.getListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) DecimalType(io.trino.spi.type.DecimalType) TypeSignatureParameter(io.trino.spi.type.TypeSignatureParameter) DATE(io.trino.spi.type.DateType.DATE) REAL(io.trino.spi.type.RealType.REAL) HIVE_BINARY(io.trino.plugin.hive.HiveType.HIVE_BINARY) TypeInfoFactory.getCharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getCharTypeInfo) TypeInfoFactory.getStructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getStructTypeInfo) HIVE_DOUBLE(io.trino.plugin.hive.HiveType.HIVE_DOUBLE) TypeInfoFactory.getVarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getVarcharTypeInfo) HiveUtil.isRowType(io.trino.plugin.hive.util.HiveUtil.isRowType) Type(io.trino.spi.type.Type) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TimestampType(io.trino.spi.type.TimestampType) TypeSignatureParameter.typeParameter(io.trino.spi.type.TypeSignatureParameter.typeParameter) VarcharType(io.trino.spi.type.VarcharType) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) HIVE_TIMESTAMP(io.trino.plugin.hive.HiveType.HIVE_TIMESTAMP) Nullable(javax.annotation.Nullable) DEFAULT_PRECISION(io.trino.plugin.hive.HiveTimestampPrecision.DEFAULT_PRECISION) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) TypeSignatureParameter.namedField(io.trino.spi.type.TypeSignatureParameter.namedField) HIVE_SHORT(io.trino.plugin.hive.HiveType.HIVE_SHORT) HiveUtil.isArrayType(io.trino.plugin.hive.util.HiveUtil.isArrayType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) HIVE_LONG(io.trino.plugin.hive.HiveType.HIVE_LONG) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) HIVE_STRING(io.trino.plugin.hive.HiveType.HIVE_STRING) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo) HIVE_INT(io.trino.plugin.hive.HiveType.HIVE_INT) HIVE_BOOLEAN(io.trino.plugin.hive.HiveType.HIVE_BOOLEAN) TypeSignature.rowType(io.trino.spi.type.TypeSignature.rowType) CharType(io.trino.spi.type.CharType) TINYINT(io.trino.spi.type.TinyintType.TINYINT) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) TypeInfoFactory.getStructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getStructTypeInfo) TypeInfoFactory.getMapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getMapTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) TypeInfoFactory.getListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo) TypeInfoFactory.getCharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getCharTypeInfo) TypeInfoFactory.getStructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getStructTypeInfo) TypeInfoFactory.getVarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getVarcharTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) HiveUtil.isMapType(io.trino.plugin.hive.util.HiveUtil.isMapType) CharType.createCharType(io.trino.spi.type.CharType.createCharType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) DecimalType(io.trino.spi.type.DecimalType) HiveUtil.isRowType(io.trino.plugin.hive.util.HiveUtil.isRowType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TimestampType(io.trino.spi.type.TimestampType) VarcharType(io.trino.spi.type.VarcharType) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) HiveUtil.isArrayType(io.trino.plugin.hive.util.HiveUtil.isArrayType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) TypeSignature.rowType(io.trino.spi.type.TypeSignature.rowType) CharType(io.trino.spi.type.CharType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) NamedTypeSignature(io.trino.spi.type.NamedTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureParameter(io.trino.spi.type.TypeSignatureParameter) TypeInfoFactory.getListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) TypeInfoFactory.getMapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getMapTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) TrinoException(io.trino.spi.TrinoException) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)

Example 3 with HiveTimestampPrecision

use of io.trino.plugin.hive.HiveTimestampPrecision in project trino by trinodb.

the class HiveBucketing method getHiveBucketHandle.

public static Optional<HiveBucketHandle> getHiveBucketHandle(ConnectorSession session, Table table, TypeManager typeManager) {
    if (table.getParameters().containsKey(SPARK_TABLE_PROVIDER_KEY)) {
        return Optional.empty();
    }
    Optional<HiveBucketProperty> hiveBucketProperty = table.getStorage().getBucketProperty();
    if (hiveBucketProperty.isEmpty()) {
        return Optional.empty();
    }
    if (!isSupportedBucketing(table)) {
        return Optional.empty();
    }
    HiveTimestampPrecision timestampPrecision = getTimestampPrecision(session);
    Map<String, HiveColumnHandle> map = getRegularColumnHandles(table, typeManager, timestampPrecision).stream().collect(Collectors.toMap(HiveColumnHandle::getName, identity()));
    ImmutableList.Builder<HiveColumnHandle> bucketColumns = ImmutableList.builder();
    for (String bucketColumnName : hiveBucketProperty.get().getBucketedBy()) {
        HiveColumnHandle bucketColumnHandle = map.get(bucketColumnName);
        if (bucketColumnHandle == null) {
            throw new TrinoException(HIVE_INVALID_METADATA, format("Table '%s.%s' is bucketed on non-existent column '%s'", table.getDatabaseName(), table.getTableName(), bucketColumnName));
        }
        bucketColumns.add(bucketColumnHandle);
    }
    BucketingVersion bucketingVersion = hiveBucketProperty.get().getBucketingVersion();
    int bucketCount = hiveBucketProperty.get().getBucketCount();
    List<SortingColumn> sortedBy = hiveBucketProperty.get().getSortedBy();
    return Optional.of(new HiveBucketHandle(bucketColumns.build(), bucketingVersion, bucketCount, bucketCount, sortedBy));
}
Also used : SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) HiveBucketHandle(io.trino.plugin.hive.HiveBucketHandle) TrinoException(io.trino.spi.TrinoException) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle)

Example 4 with HiveTimestampPrecision

use of io.trino.plugin.hive.HiveTimestampPrecision in project trino by trinodb.

the class TestHiveCompatibility method testTimestampFieldWrittenByOptimizedParquetWriterCannotBeReadByHive.

@Test(groups = STORAGE_FORMATS_DETAILED)
public void testTimestampFieldWrittenByOptimizedParquetWriterCannotBeReadByHive() throws Exception {
    // only admin user is allowed to change session properties
    setAdminRole(onTrino().getConnection());
    setSessionProperty(onTrino().getConnection(), "hive.experimental_parquet_optimized_writer_enabled", "true");
    String tableName = "parquet_table_timestamp_created_in_trino";
    onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName);
    onTrino().executeQuery("CREATE TABLE " + tableName + "(timestamp_precision varchar, a_timestamp timestamp) WITH (format = 'PARQUET')");
    for (HiveTimestampPrecision hiveTimestampPrecision : HiveTimestampPrecision.values()) {
        setSessionProperty(onTrino().getConnection(), "hive.timestamp_precision", hiveTimestampPrecision.name());
        onTrino().executeQuery("INSERT INTO " + tableName + " VALUES ('" + hiveTimestampPrecision.name() + "', TIMESTAMP '2021-01-05 12:01:00.111901001')");
        // Hive expects `INT96` (deprecated on Parquet) for timestamp values
        assertQueryFailure(() -> onHive().executeQuery("SELECT a_timestamp FROM " + tableName + " WHERE timestamp_precision = '" + hiveTimestampPrecision.name() + "'")).hasMessageMatching(".*java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.hive.serde2.io.(TimestampWritable|TimestampWritableV2)");
    }
    onTrino().executeQuery(format("DROP TABLE %s", tableName));
}
Also used : HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) Test(org.testng.annotations.Test)

Example 5 with HiveTimestampPrecision

use of io.trino.plugin.hive.HiveTimestampPrecision in project trino by trinodb.

the class TestHiveStorageFormats method assertStructTimestamps.

/**
 * Assertions for tables created by {@link #createStructTimestampTable(String, StorageFormat)}
 */
private void assertStructTimestamps(String tableName, Collection<TimestampAndPrecision> data) {
    SoftAssertions softly = new SoftAssertions();
    for (HiveTimestampPrecision precision : HiveTimestampPrecision.values()) {
        setTimestampPrecision(precision);
        // Check that the correct types are read
        String type = format("timestamp(%d)", precision.getPrecision());
        softly.check(() -> assertThat(onTrino().executeQuery(format("SELECT" + "   typeof(arr)," + "   typeof(map)," + "   typeof(row)," + "   typeof(nested)" + " FROM %s" + " LIMIT 1", tableName))).as("timestamp container types").containsOnly(row(format("array(%s)", type), format("map(%1$s, %1$s)", type), format("row(col %s)", type), format("array(map(%1$s, row(col array(%1$s))))", type))));
        // Check the values as varchar
        softly.check(() -> assertThat(onTrino().executeQuery(format("SELECT" + "   id," + "   CAST(arr[1] AS VARCHAR)," + // key
        "   CAST(map_entries(map)[1][1] AS VARCHAR)," + // value
        "   CAST(map_entries(map)[1][2] AS VARCHAR)," + "   CAST(row.col AS VARCHAR)," + // key
        "   CAST(map_entries(nested[1])[1][1] AS VARCHAR)," + // value
        "   CAST(map_entries(nested[1])[1][2].col[1] AS VARCHAR)" + " FROM %s" + " ORDER BY id", tableName))).as("timestamp containers as varchar").containsExactlyInOrder(data.stream().sorted(comparingInt(TimestampAndPrecision::getId)).map(e -> new Row(Lists.asList(e.getId(), nCopies(6, e.getReadValue(precision)).toArray()))).collect(toList())));
        // Check the values directly
        softly.check(() -> assertThat(onTrino().executeQuery(format("SELECT" + "   id," + "   arr[1]," + // key
        "   map_entries(map)[1][1]," + // value
        "   map_entries(map)[1][2]," + "   row.col," + // key
        "   map_entries(nested[1])[1][1]," + // value
        "   map_entries(nested[1])[1][2].col[1]" + " FROM %s" + " ORDER BY id", tableName))).as("timestamp containers").containsExactlyInOrder(data.stream().sorted(comparingInt(TimestampAndPrecision::getId)).map(e -> new Row(Lists.asList(e.getId(), nCopies(6, Timestamp.valueOf(e.getReadValue(precision))).toArray()))).collect(toList())));
    }
    softly.assertAll();
}
Also used : STORAGE_FORMATS_DETAILED(io.trino.tests.product.TestGroups.STORAGE_FORMATS_DETAILED) Arrays(java.util.Arrays) Connection(java.sql.Connection) HMS_ONLY(io.trino.tests.product.TestGroups.HMS_ONLY) Inject(com.google.inject.Inject) Test(org.testng.annotations.Test) QueryResult(io.trino.tempto.query.QueryResult) Matcher(java.util.regex.Matcher) ERROR_COMMITTING_WRITE_TO_HIVE_MATCH(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_MATCH) Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.nCopies(java.util.Collections.nCopies) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QueryAssert.assertThat(io.trino.tempto.assertions.QueryAssert.assertThat) ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE) Set(java.util.Set) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) DataSize(io.airlift.units.DataSize) ParquetWriter(org.apache.parquet.hadoop.ParquetWriter) List(java.util.List) Stream(java.util.stream.Stream) InputStream.nullInputStream(java.io.InputStream.nullInputStream) JdbcDriverUtils(io.trino.tests.product.utils.JdbcDriverUtils) Pattern(java.util.regex.Pattern) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) SoftAssertions(org.assertj.core.api.SoftAssertions) DataProvider(org.testng.annotations.DataProvider) NANOSECONDS(io.trino.plugin.hive.HiveTimestampPrecision.NANOSECONDS) JdbcDriverUtils.setSessionProperty(io.trino.tests.product.utils.JdbcDriverUtils.setSessionProperty) QueryExecutors.onHive(io.trino.tests.product.utils.QueryExecutors.onHive) TemporaryHiveTable.randomTableSuffix(io.trino.tests.product.hive.util.TemporaryHiveTable.randomTableSuffix) JDBCType(java.sql.JDBCType) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) Verify.verify(com.google.common.base.Verify.verify) HdfsClient(io.trino.tempto.hadoop.hdfs.HdfsClient) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Named(javax.inject.Named) Row.row(io.trino.tempto.assertions.QueryAssert.Row.row) Row(io.trino.tempto.assertions.QueryAssert.Row) Flaky(io.trino.testng.services.Flaky) Comparator.comparingInt(java.util.Comparator.comparingInt) Iterator(java.util.Iterator) ProductTest(io.trino.tempto.ProductTest) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) QueryExecutors.onTrino(io.trino.tests.product.utils.QueryExecutors.onTrino) QueryExecutionException(io.trino.tempto.query.QueryExecutionException) MICROSECONDS(io.trino.plugin.hive.HiveTimestampPrecision.MICROSECONDS) QueryExecutor.param(io.trino.tempto.query.QueryExecutor.param) Collectors.toList(java.util.stream.Collectors.toList) QueryParam(io.trino.tempto.query.QueryExecutor.QueryParam) MILLISECONDS(io.trino.plugin.hive.HiveTimestampPrecision.MILLISECONDS) STORAGE_FORMATS(io.trino.tests.product.TestGroups.STORAGE_FORMATS) SoftAssertions(org.assertj.core.api.SoftAssertions) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) Row(io.trino.tempto.assertions.QueryAssert.Row)

Aggregations

HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 TrinoException (io.trino.spi.TrinoException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)2 Type (io.trino.spi.type.Type)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 Test (org.testng.annotations.Test)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Splitter (com.google.common.base.Splitter)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Lists (com.google.common.collect.Lists)1 Maps.immutableEntry (com.google.common.collect.Maps.immutableEntry)1 Streams (com.google.common.collect.Streams)1 Inject (com.google.inject.Inject)1 DataSize (io.airlift.units.DataSize)1