You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/08/01 08:42:13 UTC
[GitHub] [flink] luoyuxia commented on a diff in pull request #19283: [FLINK-27016][hive] Improve supporting for complex data type for Hive dialect
luoyuxia commented on code in PR #19283:
URL: https://github.com/apache/flink/pull/19283#discussion_r934280917
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/conversion/HiveInspectors.java:
##########
@@ -435,23 +438,28 @@ public static Object toFlinkObject(ObjectInspector inspector, Object data, HiveS
List<? extends StructField> fields = structInspector.getAllStructFieldRefs();
- Row row = new Row(fields.size());
+ final Object[] fieldByPosition = new Object[fields.size()];
+
+ LinkedHashMap<String, Integer> positionByName = new LinkedHashMap<>();
// StandardStructObjectInspector.getStructFieldData in Hive-1.2.1 only accepts array or
// list as data
if (!data.getClass().isArray()
&& !(data instanceof List)
&& (inspector instanceof StandardStructObjectInspector)) {
data = new Object[] {data};
}
- for (int i = 0; i < row.getArity(); i++) {
- row.setField(
- i,
+ for (int i = 0; i < fields.size(); i++) {
+ StructField field = fields.get(i);
+ fieldByPosition[i] =
toFlinkObject(
- fields.get(i).getFieldObjectInspector(),
- structInspector.getStructFieldData(data, fields.get(i)),
- hiveShim));
+ field.getFieldObjectInspector(),
+ structInspector.getStructFieldData(data, field),
+ hiveShim);
+ positionByName.put(field.getFieldName(), i);
}
- return row;
+
+ return RowUtils.createRowWithNamedPositions(
Review Comment:
Not necessary.
I change it because when I visited the code, I thought It'll be more convenient to return a name-based Row. But I haven't realized it will degrade the perfermance .
Since no others will benefit from this change at least now, I revert this change now.
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/conversion/HiveInspectors.java:
##########
@@ -435,23 +438,28 @@ public static Object toFlinkObject(ObjectInspector inspector, Object data, HiveS
List<? extends StructField> fields = structInspector.getAllStructFieldRefs();
- Row row = new Row(fields.size());
+ final Object[] fieldByPosition = new Object[fields.size()];
+
+ LinkedHashMap<String, Integer> positionByName = new LinkedHashMap<>();
// StandardStructObjectInspector.getStructFieldData in Hive-1.2.1 only accepts array or
// list as data
if (!data.getClass().isArray()
&& !(data instanceof List)
&& (inspector instanceof StandardStructObjectInspector)) {
data = new Object[] {data};
}
- for (int i = 0; i < row.getArity(); i++) {
- row.setField(
- i,
+ for (int i = 0; i < fields.size(); i++) {
+ StructField field = fields.get(i);
+ fieldByPosition[i] =
toFlinkObject(
- fields.get(i).getFieldObjectInspector(),
- structInspector.getStructFieldData(data, fields.get(i)),
- hiveShim));
+ field.getFieldObjectInspector(),
+ structInspector.getStructFieldData(data, field),
+ hiveShim);
+ positionByName.put(field.getFieldName(), i);
}
- return row;
+
+ return RowUtils.createRowWithNamedPositions(
Review Comment:
Not necessary.
I change it because when I visited the code, I thought It'll be more convenient to return a name-based Row. But I haven't realized it will degrade the perfermance .
Since no others will benefit from this change at least now, I reverted this change now.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org