Skip to content

Commit 8aa9103

Browse files
committed
remove reflection way
Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent a706a48 commit 8aa9103

2 files changed

Lines changed: 10 additions & 38 deletions

File tree

integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/4173.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ setup:
2828
type: keyword
2929
child_num:
3030
type: integer
31+
- do:
32+
bulk:
33+
index: array-test
34+
refresh: true
35+
body:
36+
- '{"index": {}}'
37+
- '{"array_text": ["Jane Smith","hello world"],"array_keyword": [ "c++", "java" ],"array_num": [1, 2],"array_boolean": [true, false],"array_date": ["2023-01-02T22:03:34.000Z","2023-01-02T22:03:35.000Z"],"num" : 10,"parent": {"child_array_num": [1.1, 2.2], "child_array_keyword":["a a a", "b b b"], "child_num": 100}}'
38+
- '{"index": {}}'
39+
- '{"array_text": "OpenSearch PPL","array_keyword": "python","array_num": 3,"array_boolean": true,"array_date": "2023-01-02T22:03:36.000Z","num" : 11,"parent": {"child_array_num": 3.3, "child_array_keyword":"c c c", "child_num": 101}}'
3140
- do:
3241
query.settings:
3342
body:
3443
transient:
3544
plugins.calcite.enabled : true
36-
3745
---
3846
teardown:
3947
- do:
@@ -48,15 +56,6 @@ teardown:
4856
features:
4957
- headers
5058
- allowed_warnings
51-
- do:
52-
bulk:
53-
index: array-test
54-
refresh: true
55-
body:
56-
- '{"index": {}}'
57-
- '{"array_text": ["Jane Smith","hello world"],"array_keyword": [ "c++", "java" ],"array_num": [1, 2],"array_boolean": [true, false],"array_date": ["2023-01-02T22:03:34.000Z","2023-01-02T22:03:35.000Z"],"num" : 10,"parent": {"child_array_num": [1.1, 2.2], "child_array_keyword":["a a a", "b b b"], "child_num": 100}}'
58-
- '{"index": {}}'
59-
- '{"array_text": "OpenSearch PPL","array_keyword": "python","array_num": 3,"array_boolean": true,"array_date": "2023-01-02T22:03:36.000Z","num" : 11,"parent": {"child_array_num": 3.3, "child_array_keyword":"c c c", "child_num": 101}}'
6059
- do:
6160
allowed_warnings:
6261
- 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled'

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/OpenSearchExecutionEngine.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.opensearch.sql.opensearch.executor;
77

88
import com.google.common.base.Suppliers;
9-
import java.lang.reflect.Method;
109
import java.sql.PreparedStatement;
1110
import java.sql.ResultSet;
1211
import java.sql.ResultSetMetaData;
@@ -20,8 +19,6 @@
2019
import java.util.concurrent.ConcurrentHashMap;
2120
import java.util.concurrent.atomic.AtomicReference;
2221
import java.util.function.Supplier;
23-
import org.apache.calcite.avatica.AvaticaResultSet;
24-
import org.apache.calcite.avatica.util.Cursor;
2522
import org.apache.calcite.plan.RelOptUtil;
2623
import org.apache.calcite.rel.RelNode;
2724
import org.apache.calcite.rel.RelRoot;
@@ -218,29 +215,6 @@ public void execute(
218215
});
219216
}
220217

221-
/**
222-
* Retrieves column accessors from AvaticaResultSet using reflection. This method accesses the
223-
* private getAccessor method to obtain direct access to column data.
224-
*
225-
* @param rs the ResultSet to get accessors from
226-
* @param columnCount the number of columns in the ResultSet
227-
* @return list of Cursor.Accessor objects for each column
228-
* @throws SQLException if reflection fails or column access is invalid
229-
*/
230-
private List<Cursor.Accessor> getAccessors(ResultSet rs, int columnCount) throws SQLException {
231-
List<Cursor.Accessor> accessorList = new ArrayList<>();
232-
try {
233-
Method method = AvaticaResultSet.class.getDeclaredMethod("getAccessor", int.class);
234-
method.setAccessible(true);
235-
for (int i = 1; i <= columnCount; i++) {
236-
accessorList.add((Cursor.Accessor) method.invoke(rs, i));
237-
}
238-
} catch (Exception e) {
239-
throw new SQLException("Unable to get accessors", e);
240-
}
241-
return accessorList;
242-
}
243-
244218
/**
245219
* Process values recursively, handling geo points and nested maps. Geo points are converted to
246220
* OpenSearchExprGeoPointValue. Maps are recursively processed to handle nested structures.
@@ -282,7 +256,6 @@ private void buildResultSet(
282256
// Get the ResultSet metadata to know about columns
283257
ResultSetMetaData metaData = resultSet.getMetaData();
284258
int columnCount = metaData.getColumnCount();
285-
List<Cursor.Accessor> accessorList = getAccessors(resultSet, columnCount);
286259
List<RelDataType> fieldTypes =
287260
rowTypes.getFieldList().stream().map(RelDataTypeField::getType).toList();
288261
List<ExprValue> values = new ArrayList<>();
@@ -292,7 +265,7 @@ private void buildResultSet(
292265
// Loop through each column
293266
for (int i = 1; i <= columnCount; i++) {
294267
String columnName = metaData.getColumnName(i);
295-
Object value = accessorList.get(i - 1).getObject();
268+
Object value = resultSet.getObject(columnName);
296269
Object converted = processValue(value);
297270
ExprValue exprValue = ExprValueUtils.fromObjectValue(converted);
298271
row.put(columnName, exprValue);

0 commit comments

Comments
 (0)