-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-28984: Replace nashorn-core with graalvm which is compatible wit… #5856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
*/ | ||
package org.apache.hadoop.hive.ql.metadata; | ||
|
||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; | ||
import org.apache.hadoop.hive.metastore.api.AlreadyExistsException; | ||
import org.apache.hadoop.hive.metastore.api.GetPartitionsFilterSpec; | ||
import org.apache.hadoop.hive.metastore.api.GetPartitionsRequest; | ||
|
@@ -28,11 +29,8 @@ | |
import org.apache.hadoop.hive.metastore.api.PartitionFilterMode; | ||
import org.apache.hadoop.hive.metastore.api.PartitionListComposingSpec; | ||
import org.apache.hadoop.hive.metastore.api.PartitionSpec; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.graalvm.polyglot.Context; | ||
|
||
import javax.script.ScriptEngine; | ||
import javax.script.ScriptEngineManager; | ||
import javax.script.ScriptException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -41,7 +39,6 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.hadoop.hive.metastore.Warehouse.LOG; | ||
import static org.apache.hadoop.hive.metastore.Warehouse.makePartName; | ||
import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.makePartNameMatcher; | ||
|
||
|
@@ -50,7 +47,6 @@ | |
* via references. | ||
*/ | ||
final class PartitionTree { | ||
private static final Logger LOG = LoggerFactory.getLogger(PartitionTree.class); | ||
private Map<String, org.apache.hadoop.hive.metastore.api.Partition> parts = new LinkedHashMap<>(); | ||
private final org.apache.hadoop.hive.metastore.api.Table tTable; | ||
|
||
|
@@ -258,21 +254,20 @@ List<Partition> getPartitionsByFilter(final String filter) throws MetaException | |
return new ArrayList<>(parts.values()); | ||
} | ||
List<Partition> result = new ArrayList<>(); | ||
ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript"); | ||
if (se == null) { | ||
LOG.error("JavaScript script engine is not found, therefore partition filtering " | ||
+ "for temporary tables is disabled."); | ||
return result; | ||
} | ||
for (Map.Entry<String, Partition> entry : parts.entrySet()) { | ||
se.put("partitionName", entry.getKey()); | ||
se.put("values", entry.getValue().getValues()); | ||
try { | ||
if ((Boolean)se.eval(filter)) { | ||
result.add(entry.getValue()); | ||
try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, | ||
Context.newBuilder().allowExperimentalOptions(true) | ||
.option("js.nashorn-compat", "true") | ||
.allowAllAccess(true))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm checking this document. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @okumin thanks for the review.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll be right. What if
If GraalJS works with Hive without the option, it's better from the point of view of security. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, i removed property .allowAllAccess(true) and checked it previously, we are getting error "failed due to: Unknown identifier: get". So in our case we need to pass this field. thanks ! |
||
for (Map.Entry<String, Partition> entry : parts.entrySet()) { | ||
se.put("partitionName", entry.getKey()); | ||
se.put("values", entry.getValue().getValues()); | ||
try { | ||
if ((Boolean) se.eval(filter)) { | ||
result.add(entry.getValue()); | ||
} | ||
} catch (ScriptException e) { | ||
throw new MetaException("Incorrect partition filter"); | ||
} | ||
} catch (ScriptException e) { | ||
throw new MetaException("Incorrect partition filter"); | ||
} | ||
} | ||
return result; | ||
|
@@ -311,19 +306,17 @@ GetPartitionsResponse getPartitionsWithSpecs(GetPartitionsRequest getPartitionsR | |
matches = filterSpec.getFilters().stream().anyMatch(str -> entry.getValue().getValues().contains(str)); | ||
break; | ||
case BY_EXPR: | ||
ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript"); | ||
if (se == null) { | ||
LOG.error("JavaScript script engine is not found, therefore partition filtering " | ||
+ "for temporary tables is disabled."); | ||
break; | ||
} | ||
|
||
for (String filter : filterSpec.getFilters()) { | ||
try { | ||
se.put("partition", partition); | ||
matches = (Boolean) se.eval(filter); | ||
} catch (ScriptException e) { | ||
throw new MetaException("Error evaluating filter expression: " + e.getMessage()); | ||
try (GraalJSScriptEngine se = GraalJSScriptEngine.create(null, | ||
Context.newBuilder().allowExperimentalOptions(true) | ||
.option("js.nashorn-compat", "true") | ||
.allowAllAccess(true))) { | ||
for (String filter : filterSpec.getFilters()) { | ||
try { | ||
se.put("partition", partition); | ||
matches = (Boolean) se.eval(filter); | ||
} catch (ScriptException e) { | ||
throw new MetaException("Error evaluating filter expression: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both libraries are licensed as UPL. It's fine as it's classified as Category A.