szlta commented on a change in pull request #3242:
URL: https://github.com/apache/iceberg/pull/3242#discussion_r726084881
##########
File path:
mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergInputFormat.java
##########
@@ -100,23 +101,39 @@
.toArray(InputSplit[]::new);
}
+ // Need for testing
+ protected void checkHive3Present() {
+ Preconditions.checkArgument(MetastoreUtil.hive3PresentOnClasspath(),
"Vectorization only supported for Hive 3+");
+ }
+
+ protected RecordReader<Void, Container<Record>>
getVectorizedRecordReader(IcebergSplit icebergSplit,
+
JobConf job,
+
Reporter reporter) {
+ return (RecordReader) HIVE_VECTORIZED_RECORDREADER_CTOR.newInstance(
+ new org.apache.iceberg.mr.mapreduce.IcebergInputFormat<>(),
+ icebergSplit,
+ job,
+ reporter);
+ }
+
@Override
public RecordReader<Void, Container<Record>> getRecordReader(InputSplit
split, JobConf job,
Reporter
reporter) throws IOException {
String[] selectedColumns = ColumnProjectionUtils.getReadColumnNames(job);
job.setStrings(InputFormatConfig.SELECTED_COLUMNS, selectedColumns);
-
- if (HiveConf.getBoolVar(job,
HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED)) {
- Preconditions.checkArgument(MetastoreUtil.hive3PresentOnClasspath(),
"Vectorization only supported for Hive 3+");
-
+ // Testing if vectorization was enabled and ok for hive
+ if (HiveConf.getBoolVar(job, HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED)
&&
+ Utilities.getVectorizedRowBatchCtx(job) != null) {
+ checkHive3Present();
IcebergSplit icebergSplit = ((IcebergSplitContainer)
split).icebergSplit();
// bogus cast for favouring code reuse over syntax
- return (RecordReader) HIVE_VECTORIZED_RECORDREADER_CTOR.newInstance(
- new org.apache.iceberg.mr.mapreduce.IcebergInputFormat<>(),
+ return getVectorizedRecordReader(
icebergSplit,
job,
reporter);
} else {
+ // Forcing IN_MEMORY_DATA_MODEL to generic in case that vectorization
can not be performed by hive
+ job.setEnum(InputFormatConfig.IN_MEMORY_DATA_MODEL,
InputFormatConfig.InMemoryDataModel.GENERIC);
Review comment:
This is basically reverting what
https://github.com/apache/iceberg/blob/master/mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java#L131-L134
does.
I understand that this should be done rather here than in
HiveIcebergStorageHandler as the Hive might fall back to non-vectorized mode
after query compilation, but then let's try and do the InMemoryDataMode.HIVE
setting here to.
You could refactor this getRecordReader method here such as you construct a
boolean isVectorized variable, and call an ensureInMemoryDataModel( boolean
isVectorized) method instead.
##########
File path:
mr/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergInputFormat.java
##########
@@ -100,23 +101,39 @@
.toArray(InputSplit[]::new);
}
+ // Need for testing
+ protected void checkHive3Present() {
+ Preconditions.checkArgument(MetastoreUtil.hive3PresentOnClasspath(),
"Vectorization only supported for Hive 3+");
+ }
+
+ protected RecordReader<Void, Container<Record>>
getVectorizedRecordReader(IcebergSplit icebergSplit,
+
JobConf job,
+
Reporter reporter) {
+ return (RecordReader) HIVE_VECTORIZED_RECORDREADER_CTOR.newInstance(
+ new org.apache.iceberg.mr.mapreduce.IcebergInputFormat<>(),
+ icebergSplit,
+ job,
+ reporter);
+ }
+
@Override
public RecordReader<Void, Container<Record>> getRecordReader(InputSplit
split, JobConf job,
Reporter
reporter) throws IOException {
String[] selectedColumns = ColumnProjectionUtils.getReadColumnNames(job);
job.setStrings(InputFormatConfig.SELECTED_COLUMNS, selectedColumns);
-
- if (HiveConf.getBoolVar(job,
HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED)) {
- Preconditions.checkArgument(MetastoreUtil.hive3PresentOnClasspath(),
"Vectorization only supported for Hive 3+");
-
+ // Testing if vectorization was enabled and ok for hive
+ if (HiveConf.getBoolVar(job, HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED)
&&
+ Utilities.getVectorizedRowBatchCtx(job) != null) {
+ checkHive3Present();
Review comment:
Can we perhaps call this once per class loading? i.e. call is in a
static block and save the state of Hive3 being present into a static boolean
variable perhaps as this won't change until JVM termination anyways.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]