-
Notifications
You must be signed in to change notification settings - Fork 3k
Enable Hive3 builds for iceberg-mr and iceberg-hive-metastore #1478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fc8314c
Hive: Create new mr-hive3 module which builds with Hive3/Hadoop3
marton-bod 6b35a33
Hive: Rename mr-hive3 to hive3; Use reflection helpers from iceberg-c…
marton-bod 4fc53d0
update comment
marton-bod 6a4ea19
Use Instant/epoch days to create date/timestamp objects in tests; Ref…
marton-bod 880009a
Extract epochDays and epochMillis
marton-bod 196e917
Avoid concurrency issues between iceberg-mr and iceberg-hive3 tests
marton-bod 7c055ad
Shutdown HMSHandler directly instead of using reflective call
marton-bod 62da1a6
Hive: Instantiate metastore once per test class for StorageHandler te…
marton-bod 1d7dc49
Add metastore uris as system prop; Remove multiple metastores workaround
marton-bod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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.hive; | ||
|
|
||
| public class MetastoreUtil { | ||
|
|
||
| // this class is unique to Hive3 and cannot be found in Hive2, therefore a good proxy to see if | ||
| // we are working against Hive3 dependencies | ||
| private static final String HIVE3_UNIQUE_CLASS = "org.apache.hadoop.hive.serde2.io.DateWritableV2"; | ||
|
|
||
| private static final boolean HIVE3_PRESENT_ON_CLASSPATH = detectHive3(); | ||
|
|
||
marton-bod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private MetastoreUtil() { | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if Hive3 dependencies are found on classpath, false otherwise. | ||
| */ | ||
| public static boolean hive3PresentOnClasspath() { | ||
marton-bod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return HIVE3_PRESENT_ON_CLASSPATH; | ||
| } | ||
|
|
||
| private static boolean detectHive3() { | ||
| try { | ||
| Class.forName(HIVE3_UNIQUE_CLASS); | ||
| return true; | ||
| } catch (ClassNotFoundException e) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ava/org/apache/iceberg/mr/hive/serde/objectinspector/IcebergDateObjectInspectorHive3.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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 java.time.LocalDate; | ||
| import org.apache.hadoop.hive.common.type.Date; | ||
| import org.apache.hadoop.hive.serde2.io.DateWritableV2; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; | ||
| import org.apache.iceberg.util.DateTimeUtil; | ||
|
|
||
| public final class IcebergDateObjectInspectorHive3 extends AbstractPrimitiveJavaObjectInspector | ||
| implements DateObjectInspector { | ||
|
|
||
| private static final IcebergDateObjectInspectorHive3 INSTANCE = new IcebergDateObjectInspectorHive3(); | ||
|
|
||
| public static IcebergDateObjectInspectorHive3 get() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| private IcebergDateObjectInspectorHive3() { | ||
| super(TypeInfoFactory.dateTypeInfo); | ||
| } | ||
|
|
||
| @Override | ||
| public Date getPrimitiveJavaObject(Object o) { | ||
| if (o == null) { | ||
| return null; | ||
| } | ||
| LocalDate date = (LocalDate) o; | ||
| return Date.ofEpochDay(DateTimeUtil.daysFromDate(date)); | ||
| } | ||
|
|
||
| @Override | ||
| public DateWritableV2 getPrimitiveWritableObject(Object o) { | ||
| return o == null ? null : new DateWritableV2(DateTimeUtil.daysFromDate((LocalDate) o)); | ||
| } | ||
|
|
||
| @Override | ||
| public Object copyObject(Object o) { | ||
| return o == null ? null : new Date((Date) o); | ||
| } | ||
|
|
||
| } |
90 changes: 90 additions & 0 deletions
90
...rg/apache/iceberg/mr/hive/serde/objectinspector/IcebergTimestampObjectInspectorHive3.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * 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 java.time.LocalDateTime; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneOffset; | ||
| import org.apache.hadoop.hive.common.type.Timestamp; | ||
| 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.TypeInfoFactory; | ||
|
|
||
| public abstract class IcebergTimestampObjectInspectorHive3 extends AbstractPrimitiveJavaObjectInspector | ||
| implements TimestampObjectInspector { | ||
|
|
||
| private static final IcebergTimestampObjectInspectorHive3 INSTANCE_WITH_ZONE = | ||
| new IcebergTimestampObjectInspectorHive3() { | ||
| @Override | ||
| LocalDateTime toLocalDateTime(Object o) { | ||
| return ((OffsetDateTime) o).toLocalDateTime(); | ||
| } | ||
| }; | ||
|
|
||
| private static final IcebergTimestampObjectInspectorHive3 INSTANCE_WITHOUT_ZONE = | ||
| new IcebergTimestampObjectInspectorHive3() { | ||
| @Override | ||
| LocalDateTime toLocalDateTime(Object o) { | ||
| return (LocalDateTime) o; | ||
| } | ||
| }; | ||
|
|
||
| public static IcebergTimestampObjectInspectorHive3 get(boolean adjustToUTC) { | ||
| return adjustToUTC ? INSTANCE_WITH_ZONE : INSTANCE_WITHOUT_ZONE; | ||
| } | ||
|
|
||
| private IcebergTimestampObjectInspectorHive3() { | ||
| super(TypeInfoFactory.timestampTypeInfo); | ||
| } | ||
|
|
||
|
|
||
| abstract LocalDateTime toLocalDateTime(Object object); | ||
|
|
||
| @Override | ||
| public Timestamp getPrimitiveJavaObject(Object o) { | ||
| if (o == null) { | ||
| return null; | ||
| } | ||
| LocalDateTime time = toLocalDateTime(o); | ||
| Timestamp timestamp = Timestamp.ofEpochMilli(time.toInstant(ZoneOffset.UTC).toEpochMilli()); | ||
| timestamp.setNanos(time.getNano()); | ||
| return timestamp; | ||
| } | ||
|
|
||
| @Override | ||
| public TimestampWritableV2 getPrimitiveWritableObject(Object o) { | ||
| Timestamp ts = getPrimitiveJavaObject(o); | ||
| return ts == null ? null : new TimestampWritableV2(ts); | ||
| } | ||
|
|
||
| @Override | ||
| public Object copyObject(Object o) { | ||
| if (o == null) { | ||
| return null; | ||
| } | ||
|
|
||
| Timestamp ts = (Timestamp) o; | ||
| Timestamp copy = new Timestamp(ts); | ||
| copy.setNanos(ts.getNanos()); | ||
| return copy; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.