kasakrisz commented on code in PR #4330:
URL: https://github.com/apache/hive/pull/4330#discussion_r1197744904
##########
hplsql/src/main/java/org/apache/hive/hplsql/Exec.java:
##########
@@ -1822,8 +1826,12 @@ public List<Table> intoTables(ParserRuleContext ctx,
List<String> names) {
* User-defined function in a SQL query
*/
public void execSql(String name, HplsqlParser.Expr_func_paramsContext ctx) {
- if (execUserSql(ctx, name)) {
- return;
+ try {
+ if (execUserSql(ctx, name)) {
+ return;
+ }
+ } catch (TException e) {
+ throw new HplValidationException(ctx, ExceptionUtils.getStackTrace(e));
Review Comment:
What is the reason not to extend `HplValidationException` with a constructor
which receives `Throwable cause` to wrap the original exception?
##########
hplsql/src/main/java/org/apache/hive/hplsql/udf/Udf.java:
##########
@@ -66,48 +64,23 @@ public ObjectInspector initialize(ObjectInspector[]
arguments) throws UDFArgumen
if (!(arguments[0] instanceof StringObjectInspector)) {
throw new UDFArgumentException("First argument must be a string");
}
- SessionState sessionState = SessionState.get();
- if (sessionState != null) {
- // we are still in HiveServer, get the source of the HplSQL function and
store it.
- functionDefinition = loadSource(sessionState,
functionName(arguments[0]));
- }
queryOI = (StringObjectInspector)arguments[0];
+ funcDefOI = (StringObjectInspector)arguments[arguments.length-1];
argumentsOI = arguments;
return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
}
- protected String loadSource(SessionState sessionState, String functionName)
throws UDFArgumentException {
- Exec exec = sessionState.getDynamicVar(Exec.class);
- try {
- StoredProcedure storedProcedure = exec.getMsc().getStoredProcedure(
- new StoredProcedureRequest(
- SessionState.get().getCurrentCatalog(),
- SessionState.get().getCurrentDatabase(),
- functionName));
- return storedProcedure != null ? storedProcedure.getSource() : null;
- } catch (TException e) {
- throw new UDFArgumentException(e);
- }
- }
-
- protected String functionName(ObjectInspector argument) {
- ConstantObjectInspector inspector = (ConstantObjectInspector) (argument);
- String functionCall = inspector.getWritableConstantValue().toString();
- return functionCall.split("\\(")[0].toUpperCase();
- }
-
/**
* Execute UDF
*/
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
- if (exec == null) {
- exec = new Exec();
Review Comment:
I saw that initializing the `Exec` instance is moved to the constructor of
`Udf`. Could you please elaborate this change?
##########
hplsql/src/main/java/org/apache/hive/hplsql/udf/Udf.java:
##########
@@ -66,48 +64,23 @@ public ObjectInspector initialize(ObjectInspector[]
arguments) throws UDFArgumen
if (!(arguments[0] instanceof StringObjectInspector)) {
throw new UDFArgumentException("First argument must be a string");
}
- SessionState sessionState = SessionState.get();
- if (sessionState != null) {
- // we are still in HiveServer, get the source of the HplSQL function and
store it.
- functionDefinition = loadSource(sessionState,
functionName(arguments[0]));
- }
queryOI = (StringObjectInspector)arguments[0];
+ funcDefOI = (StringObjectInspector)arguments[arguments.length-1];
argumentsOI = arguments;
return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
}
- protected String loadSource(SessionState sessionState, String functionName)
throws UDFArgumentException {
- Exec exec = sessionState.getDynamicVar(Exec.class);
- try {
- StoredProcedure storedProcedure = exec.getMsc().getStoredProcedure(
- new StoredProcedureRequest(
- SessionState.get().getCurrentCatalog(),
- SessionState.get().getCurrentDatabase(),
- functionName));
- return storedProcedure != null ? storedProcedure.getSource() : null;
- } catch (TException e) {
- throw new UDFArgumentException(e);
- }
- }
-
- protected String functionName(ObjectInspector argument) {
- ConstantObjectInspector inspector = (ConstantObjectInspector) (argument);
- String functionCall = inspector.getWritableConstantValue().toString();
- return functionCall.split("\\(")[0].toUpperCase();
- }
-
/**
* Execute UDF
*/
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
- if (exec == null) {
- exec = new Exec();
- exec.setQueryExecutor(QueryExecutor.DISABLED);
- exec.init();
- if (functionDefinition != null) { // if it's null, it can be a built-in
function
- exec.parseAndEval(Arguments.script(functionDefinition));
- }
+ if (functionDefinition == null) { // if it's null, it can be a built-in
function
+ int idx = arguments.length-1;
+ setParameterForPrimitiveTypeArgument(":" + idx, arguments[idx].get(),
funcDefOI);
+ functionDefinition =
funcDefOI.getPrimitiveJavaObject(arguments[idx].get());
+ LOG.info("functionDefinition: {}", functionDefinition);
Review Comment:
Does `info` level is necessary? What happens if the function is called on a
1M record table on each row?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]