|
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;
|
| 32 | +import org.graalvm.polyglot.Context; |
| 33 | + |
31 | 34 | import org.slf4j.Logger;
|
32 | 35 | import org.slf4j.LoggerFactory;
|
33 | 36 |
|
34 |
| -import javax.script.ScriptEngine; |
35 |
| -import javax.script.ScriptEngineManager; |
36 | 37 | import javax.script.ScriptException;
|
37 | 38 | import java.util.ArrayList;
|
38 | 39 | import java.util.Arrays;
|
|
41 | 42 | import java.util.List;
|
42 | 43 | import java.util.Map;
|
43 | 44 |
|
44 |
| -import static org.apache.hadoop.hive.metastore.Warehouse.LOG; |
45 | 45 | import static org.apache.hadoop.hive.metastore.Warehouse.makePartName;
|
46 | 46 | import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.makePartNameMatcher;
|
47 | 47 |
|
@@ -258,21 +258,18 @@ List<Partition> getPartitionsByFilter(final String filter) throws MetaException
|
258 | 258 | return new ArrayList<>(parts.values());
|
259 | 259 | }
|
260 | 260 | 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()); |
| 261 | + try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, |
| 262 | + Context.newBuilder("js").allowAllAccess(true))) { |
| 263 | + for (Map.Entry<String, Partition> entry : parts.entrySet()) { |
| 264 | + se.put("partitionName", entry.getKey()); |
| 265 | + se.put("values", entry.getValue().getValues()); |
| 266 | + try { |
| 267 | + if ((Boolean) se.eval(filter)) { |
| 268 | + result.add(entry.getValue()); |
| 269 | + } |
| 270 | + } catch (ScriptException e) { |
| 271 | + throw new MetaException("Incorrect partition filter"); |
273 | 272 | }
|
274 |
| - } catch (ScriptException e) { |
275 |
| - throw new MetaException("Incorrect partition filter"); |
276 | 273 | }
|
277 | 274 | }
|
278 | 275 | return result;
|
@@ -311,19 +308,15 @@ GetPartitionsResponse getPartitionsWithSpecs(GetPartitionsRequest getPartitionsR
|
311 | 308 | matches = filterSpec.getFilters().stream().anyMatch(str -> entry.getValue().getValues().contains(str));
|
312 | 309 | break;
|
313 | 310 | 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()); |
| 311 | + try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, |
| 312 | + Context.newBuilder("js").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