-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[native] Handle NULLIF without the need for specialForm #19791
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
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 @@ | |
| import com.facebook.presto.common.type.Type; | ||
| import com.facebook.presto.expressions.RowExpressionRewriter; | ||
| import com.facebook.presto.expressions.RowExpressionTreeRewriter; | ||
| import com.facebook.presto.metadata.FunctionAndTypeManager; | ||
| import com.facebook.presto.spi.VariableAllocator; | ||
| import com.facebook.presto.spi.function.FunctionMetadata; | ||
| import com.facebook.presto.spi.function.SqlFunctionId; | ||
|
|
@@ -82,31 +83,34 @@ public static Expression getSqlFunctionExpression( | |
| public static RowExpression getSqlFunctionRowExpression( | ||
| FunctionMetadata functionMetadata, | ||
| SqlInvokedScalarFunctionImplementation implementation, | ||
| FunctionAndTypeResolver functionAndTypeResolver, | ||
| FunctionAndTypeManager functionAndTypeManager, | ||
| SqlFunctionProperties sqlFunctionProperties, | ||
| Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, | ||
| List<RowExpression> arguments) | ||
| { | ||
| VariableAllocator variableAllocator = new VariableAllocator(); | ||
| Map<String, VariableReferenceExpression> argumentVariables = allocateFunctionArgumentVariables(functionMetadata, functionAndTypeResolver, variableAllocator); | ||
| Expression expression = getSqlFunctionImplementationExpression(functionMetadata, implementation, functionAndTypeResolver, variableAllocator, sqlFunctionProperties, argumentVariables); | ||
| Map<String, VariableReferenceExpression> argumentVariables = allocateFunctionArgumentVariables(functionMetadata, functionAndTypeManager.getFunctionAndTypeResolver(), variableAllocator); | ||
| Expression expression = getSqlFunctionImplementationExpression(functionMetadata, implementation, functionAndTypeManager.getFunctionAndTypeResolver(), variableAllocator, sqlFunctionProperties, argumentVariables); | ||
|
|
||
| // Translate to row expression | ||
| return SqlFunctionArgumentBinder.bindFunctionArguments( | ||
| SqlToRowExpressionTranslator.translate( | ||
| expression, | ||
| analyzeSqlFunctionExpression( | ||
| functionAndTypeResolver, | ||
| functionAndTypeManager.getFunctionAndTypeResolver(), | ||
| sqlFunctionProperties, | ||
| expression, | ||
| argumentVariables.values().stream() | ||
| .collect(toImmutableMap(VariableReferenceExpression::getName, VariableReferenceExpression::getType))).getExpressionTypes(), | ||
| ImmutableMap.of(), | ||
| functionAndTypeResolver, | ||
| functionAndTypeManager, | ||
| Optional.empty(), | ||
| Optional.empty(), | ||
| sqlFunctionProperties, | ||
| sessionFunctions, | ||
| // TODO: use session to determine if this is a native query | ||
|
Contributor
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. Why can't we address this TODO now?
Member
Author
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. Detailed conversation in this thread: https://github.com/prestodb/presto/pull/19791/files/189afe0a571d7ee128f242fd803a6098d967861b#r1243767843 In short,
Contributor
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. the solution would be to add the isNative flag to the connector session and pass it through when we create the connector session. I think that's a very reasonable to do, and there may be other places that would want to handle things differently depending on the native flag too, so could be generally useful. |
||
| // https://github.com/prestodb/presto/issues/20008 | ||
| false, | ||
|
Contributor
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. is this safe to assume it's not native?
Member
Author
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 don't see this code path being triggered in native path.
Contributor
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 think these can be invoked from native flow if someone uses a sql function that uses NULLIF in its implementation. And seems like an easy place for bugs to lurk.
Contributor
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. Could this be because all the native tests set configuration "inline-sql-functions" to false ? https://github.com/prestodb/presto/blob/master/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/NativeQueryRunnerUtils.java#L32 Ideally, we should try to avoid such properties/configurations. But is it possible to use that property instead in this rule ?
Member
Author
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. @aditi-pandit Can you please elaborate what do you mean by
Contributor
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. @vermapratyush : I'm not super familiar with optimizer code, but it is possible that instead of hardcoding to false, we get the value for inline-sql-functions property at a higher level (or here itself if there is access to it) and use that instead in this code ?
Member
Author
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. The issue with |
||
| new SqlToRowExpressionTranslator.Context()), | ||
| functionMetadata.getArgumentNames().get(), | ||
| arguments, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.