Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hive.common.type;

public class TimestampNano extends Timestamp {

public TimestampNano(Timestamp ts) {
super(ts);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hive.common.type;

import java.time.ZonedDateTime;

public class TimestampNanoTZ extends TimestampTZ {
public TimestampNanoTZ(ZonedDateTime zonedDateTime) {
super(zonedDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ Type convertType(TypeInfo typeInfo, String defaultValue) {
case DECIMAL:
DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
return Types.DecimalType.of(decimalTypeInfo.precision(), decimalTypeInfo.scale());
case TIMESTAMP_NS:
return Types.TimestampNanoType.withoutZone();
case TIMESTAMPTZ_NS:
return Types.TimestampNanoType.withZone();
case INTERVAL_YEAR_MONTH:
case INTERVAL_DAY_TIME:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ public static String convertToTypeString(Type type) {
return String.format("map<%s,%s>", convert(mapType.keyType()), convert(mapType.valueType()));
case VARIANT:
return "variant";
case TIMESTAMP_NANO:
Types.TimestampNanoType nanoType = (Types.TimestampNanoType) type;
if (nanoType.shouldAdjustToUTC()) {
return "nanosecond timestamp with local time zone";
}
return "nanosecond timestamp";
default:
throw new UnsupportedOperationException(type + " is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iceberg.mr.hive.serde.objectinspector;

import org.apache.hadoop.hive.common.type.Timestamp;
import org.apache.hadoop.hive.common.type.TimestampNano;
import org.apache.hadoop.hive.serde2.io.TimestampNanoWritable;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;

public class IcebergNanosecondTimestampObjectInspectorHive3 extends IcebergTimestampObjectInspectorHive3 {

private static final IcebergNanosecondTimestampObjectInspectorHive3 INSTANCE =
new IcebergNanosecondTimestampObjectInspectorHive3();

public static IcebergNanosecondTimestampObjectInspectorHive3 get() {
return INSTANCE;
}

private IcebergNanosecondTimestampObjectInspectorHive3() {
super(TypeInfoFactory.timestampNanoTypeInfo);
}

@Override
public TimestampNano getPrimitiveJavaObject(Object o) {
Timestamp timestamp = super.getPrimitiveJavaObject(o);
if (timestamp == null) {
return null;
}
return new TimestampNano(timestamp);
}

@Override
public TimestampNanoWritable getPrimitiveWritableObject(Object o) {
TimestampNano ts = getPrimitiveJavaObject(o);
return ts == null ? null : new TimestampNanoWritable(ts);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iceberg.mr.hive.serde.objectinspector;

import org.apache.hadoop.hive.common.type.TimestampNanoTZ;
import org.apache.hadoop.hive.common.type.TimestampTZ;
import org.apache.hadoop.hive.serde2.io.TimestampNanoTZWritable;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;

public class IcebergNanosecondTimestampWithZoneObjectInspectorHive3
extends IcebergTimestampWithZoneObjectInspectorHive3 {

private static final IcebergNanosecondTimestampWithZoneObjectInspectorHive3 INSTANCE =
new IcebergNanosecondTimestampWithZoneObjectInspectorHive3();

public static IcebergNanosecondTimestampWithZoneObjectInspectorHive3 get() {
return INSTANCE;
}

private IcebergNanosecondTimestampWithZoneObjectInspectorHive3() {
super(TypeInfoFactory.timestampNanosTZTypeInfo);
}

@Override
public TimestampNanoTZ getPrimitiveJavaObject(Object o) {
TimestampTZ ttz = super.getPrimitiveJavaObject(o);
if (ttz == null) {
return null;
}
return new TimestampNanoTZ(ttz.getZonedDateTime());
}

@Override
public TimestampNanoTZWritable getPrimitiveWritableObject(Object o) {
TimestampNanoTZ tsTz = getPrimitiveJavaObject(o);
return tsTz == null ? null : new TimestampNanoTZWritable(tsTz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public ObjectInspector primitive(Type.PrimitiveType primitiveType) {
return adjustToUTC ? TIMESTAMP_INSPECTOR_WITH_TZ : TIMESTAMP_INSPECTOR;
case TIME:
return IcebergTimeObjectInspector.get();
case TIMESTAMP_NANO:
boolean adjust = ((Types.TimestampNanoType) primitiveType).shouldAdjustToUTC();
return adjust ?
IcebergNanosecondTimestampWithZoneObjectInspectorHive3.get() :
IcebergNanosecondTimestampObjectInspectorHive3.get();
default:
throw new IllegalArgumentException(primitiveType.typeId() + " type is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.hadoop.hive.serde2.io.TimestampWritableV2;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;


Expand All @@ -42,6 +43,10 @@ private IcebergTimestampObjectInspectorHive3() {
super(TypeInfoFactory.timestampTypeInfo);
}

protected IcebergTimestampObjectInspectorHive3(PrimitiveTypeInfo typeInfo) {
super(typeInfo);
}

@Override
public LocalDateTime convert(Object o) {
if (o == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hadoop.hive.serde2.io.TimestampLocalTZWritable;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampLocalTZObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TimestampLocalTZTypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;

Expand All @@ -43,6 +44,10 @@ private IcebergTimestampWithZoneObjectInspectorHive3() {
super(TypeInfoFactory.timestampLocalTZTypeInfo);
}

protected IcebergTimestampWithZoneObjectInspectorHive3(PrimitiveTypeInfo typeInfo) {
super(typeInfo);
}

@Override
public OffsetDateTime convert(Object o) {
if (o == null) {
Expand Down
46 changes: 46 additions & 0 deletions iceberg/iceberg-handler/src/test/queries/positive/timestamp_ns.q
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Mask random uuid
--! qt:replace:/(\s+'uuid'=')\S+('\s*)/$1#Masked#$2/
--! qt:replace:/(\s+uuid\s+)\S+/$1#Masked#/
-- Mask random snapshot id
--! qt:replace:/('current-snapshot-id'=')\d+/$1#SnapshotId#/
-- Mask current-snapshot-timestamp-ms
--! qt:replace:/('current-snapshot-timestamp-ms'=')\d+/$1#Masked#/
-- Mask iceberg version
--! qt:replace:/("iceberg-version":")(\w+\s\w+\s\d+\.\d+\.\d+\s\(\w+\s\w+\))/$1#Masked#/
-- Mask added-files-size
--! qt:replace:/(\S\"added-files-size":")(\d+)(")/$1#Masked#$3/
-- Mask total-files-size
--! qt:replace:/(\S\"total-files-size":")(\d+)(")/$1#Masked#$3/

CREATE TABLE t (
ts_us timestamp,
ts_ns nanosecond timestamp,
ts_tz_us timestamp with local time zone,
ts_tz_ns nanosecond timestamp with local time zone
)
STORED BY ICEBERG
TBLPROPERTIES ('format-version'='3');

SHOW CREATE TABLE t;
DESCRIBE t;

INSERT INTO t VALUES (
'2025-12-18 10:15:30.123456789',
'2025-12-18 10:15:30.123456789',
'2025-12-18 10:15:30.123456789',
'2025-12-18 10:15:30.123456789'
);

SELECT ts_ns FROM t ORDER BY ts_ns;
SELECT ts_tz_ns FROM t ORDER BY ts_tz_ns;
SELECT CAST(ts_ns AS STRING) FROM t;
SELECT CAST(ts_tz_ns AS STRING) FROM t;

SELECT * FROM t;

CREATE TABLE tgt STORED BY ICEBERG TBLPROPERTIES ('format-version'='3') AS SELECT * FROM t;

SHOW CREATE TABLE tgt;
DESCRIBE tgt;

SELECT * FROM tgt;
Loading