|
17 | 17 | */
|
18 | 18 | package org.apache.hadoop.hive.ql.metadata;
|
19 | 19 |
|
| 20 | +import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; |
20 | 21 | import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
|
21 | 22 | import org.apache.hadoop.hive.metastore.api.GetPartitionsFilterSpec;
|
22 | 23 | import org.apache.hadoop.hive.metastore.api.GetPartitionsRequest;
|
|
28 | 29 | import org.apache.hadoop.hive.metastore.api.PartitionFilterMode;
|
29 | 30 | import org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec;
|
30 | 31 | import org.apache.hadoop.hive.metastore.api.PartitionSpec;
|
31 |
| -import org.slf4j.Logger; |
32 |
| -import org.slf4j.LoggerFactory; |
| 32 | +import org.graalvm.polyglot.Context; |
33 | 33 |
|
34 |
| -import javax.script.ScriptEngine; |
35 |
| -import javax.script.ScriptEngineManager; |
36 | 34 | import javax.script.ScriptException;
|
37 | 35 | import java.util.ArrayList;
|
38 | 36 | import java.util.Arrays;
|
|
41 | 39 | import java.util.List;
|
42 | 40 | import java.util.Map;
|
43 | 41 |
|
44 |
| -import static org.apache.hadoop.hive.metastore.Warehouse.LOG; |
45 | 42 | import static org.apache.hadoop.hive.metastore.Warehouse.makePartName;
|
46 | 43 | import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.makePartNameMatcher;
|
47 | 44 |
|
|
50 | 47 | * via references.
|
51 | 48 | */
|
52 | 49 | final class PartitionTree {
|
53 |
| - private static final Logger LOG = LoggerFactory.getLogger(PartitionTree.class); |
54 | 50 | private Map<String, org.apache.hadoop.hive.metastore.api.Partition> parts = new LinkedHashMap<>();
|
55 | 51 | private final org.apache.hadoop.hive.metastore.api.Table tTable;
|
56 | 52 |
|
@@ -258,21 +254,20 @@ List<Partition> getPartitionsByFilter(final String filter) throws MetaException
|
258 | 254 | return new ArrayList<>(parts.values());
|
259 | 255 | }
|
260 | 256 | List<Partition> result = new ArrayList<>();
|
261 |
| - ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript"); |
262 |
| - if (se == null) { |
263 |
| - LOG.error("JavaScript script engine is not found, therefore partition filtering " |
264 |
| - + "for temporary tables is disabled."); |
265 |
| - return result; |
266 |
| - } |
267 |
| - for (Map.Entry<String, Partition> entry : parts.entrySet()) { |
268 |
| - se.put("partitionName", entry.getKey()); |
269 |
| - se.put("values", entry.getValue().getValues()); |
270 |
| - try { |
271 |
| - if ((Boolean)se.eval(filter)) { |
272 |
| - result.add(entry.getValue()); |
| 257 | + try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, |
| 258 | + Context.newBuilder().allowExperimentalOptions(true) |
| 259 | + .option("js.nashorn-compat", "true") |
| 260 | + .allowAllAccess(true))) { |
| 261 | + for (Map.Entry<String, Partition> entry : parts.entrySet()) { |
| 262 | + se.put("partitionName", entry.getKey()); |
| 263 | + se.put("values", entry.getValue().getValues()); |
| 264 | + try { |
| 265 | + if ((Boolean) se.eval(filter)) { |
| 266 | + result.add(entry.getValue()); |
| 267 | + } |
| 268 | + } catch (ScriptException e) { |
| 269 | + throw new MetaException("Incorrect partition filter"); |
273 | 270 | }
|
274 |
| - } catch (ScriptException e) { |
275 |
| - throw new MetaException("Incorrect partition filter"); |
276 | 271 | }
|
277 | 272 | }
|
278 | 273 | return result;
|
@@ -311,19 +306,17 @@ GetPartitionsResponse getPartitionsWithSpecs(GetPartitionsRequest getPartitionsR
|
311 | 306 | matches = filterSpec.getFilters().stream().anyMatch(str -> entry.getValue().getValues().contains(str));
|
312 | 307 | break;
|
313 | 308 | case BY_EXPR:
|
314 |
| - ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript"); |
315 |
| - if (se == null) { |
316 |
| - LOG.error("JavaScript script engine is not found, therefore partition filtering " |
317 |
| - + "for temporary tables is disabled."); |
318 |
| - break; |
319 |
| - } |
320 |
| - |
321 |
| - for (String filter : filterSpec.getFilters()) { |
322 |
| - try { |
323 |
| - se.put("partition", partition); |
324 |
| - matches = (Boolean) se.eval(filter); |
325 |
| - } catch (ScriptException e) { |
326 |
| - throw new MetaException("Error evaluating filter expression: " + e.getMessage()); |
| 309 | + try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, |
| 310 | + Context.newBuilder().allowExperimentalOptions(true) |
| 311 | + .option("js.nashorn-compat", "true") |
| 312 | + .allowAllAccess(true))) { |
| 313 | + for (String filter : filterSpec.getFilters()) { |
| 314 | + try { |
| 315 | + se.put("partition", partition); |
| 316 | + matches = (Boolean) se.eval(filter); |
| 317 | + } catch (ScriptException e) { |
| 318 | + throw new MetaException("Error evaluating filter expression: " + e.getMessage()); |
| 319 | + } |
327 | 320 | }
|
328 | 321 | }
|
329 | 322 | break;
|
|
0 commit comments