[WIP] Interface for RowExpression translation#13483
[WIP] Interface for RowExpression translation#13483sachdevs wants to merge 1 commit intoprestodb:masterfrom
Conversation
|
|
||
| import java.util.Map; | ||
|
|
||
| public abstract class AbstractExpressionTranslator<T> |
There was a problem hiding this comment.
User will extend this class when writing their translator. It will be populated with default implementations.
| } | ||
|
|
||
| @Override | ||
| public TargetExpression<T> translateConstantExpression(ConstantExpression constantExpression, Map context) |
There was a problem hiding this comment.
Mocked functions, will implement once we get consensus on how this interface should look.
|
|
||
| import java.util.Map; | ||
|
|
||
| public class RowExpressionTranslator<T> |
There was a problem hiding this comment.
User uses this class in their ComputePushdown class (see JdbcComputePushdown.java) and calls .translate on it.
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| class RowExpressionTranslatorVisitor<T> |
There was a problem hiding this comment.
Underlying adapter for RowExpression visitor. This calls functions on the ExpressionTranslator interface. This class allows to hide internals from the user (i.e. they don't have to care about the visitor, only have to implement functions that are pertinent to their use case)
|
|
||
| import static com.facebook.presto.translator.registry.ScalarFromAnnotationsParser.removeTypeParameters; | ||
|
|
||
| public class ConstantTypeRegistry |
There was a problem hiding this comment.
For registering constant types. May consider combining Constant and Function registries. Lmk if a better way to do this.
| { | ||
| private final ImmutableMap<FunctionMetadata, MethodHandle> translators; | ||
|
|
||
| public FunctionRegistry(Class<?>... classes) |
There was a problem hiding this comment.
For registering MethodHandles to their corresponding function metadata so that they can be invoked via reflection.
There was a problem hiding this comment.
AbstractExpressionTranslator will use this class and ConstantTypeRegistry for it's default implementations of translate functions.
| import static java.lang.String.format; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ScalarFromAnnotationsParser |
There was a problem hiding this comment.
Copied from original annotation parsing classes in Scuba/Cubrick
There was a problem hiding this comment.
This needs to check how much we can reuse the existing ScalarFromAnnotationsParser. Most of the code paths are duplicated
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ScalarHeader |
There was a problem hiding this comment.
Copied from original annotation parsing classes in Scuba/Cubrick
There was a problem hiding this comment.
We don't need this. Use with existing ScalarHeader
|
|
||
| public interface ExpressionTranslator<T> | ||
| { | ||
| TargetExpression<T> translateCallExpression(CallExpression callExpression, Map<VariableReferenceExpression, ColumnHandle> context); |
There was a problem hiding this comment.
Primary way user will interact with the translation interface.
| private List<TargetExpression> params; | ||
| private Optional<T> translatedExpression; | ||
|
|
||
| public TargetExpression(Optional<T> translatedExpression) |
There was a problem hiding this comment.
Rough implementation of TargetExpression, the fields are accurate but most of these methods will be changed.
| public abstract class AbstractExpressionTranslator<T> | ||
| implements ExpressionTranslator | ||
| { | ||
| private final FunctionRegistry functionRegistry; |
There was a problem hiding this comment.
should be protected/ have protected accessors.
| import static java.lang.String.format; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ScalarFromAnnotationsParser |
There was a problem hiding this comment.
This needs to check how much we can reuse the existing ScalarFromAnnotationsParser. Most of the code paths are duplicated
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ScalarHeader |
There was a problem hiding this comment.
We don't need this. Use with existing ScalarHeader
|
|
||
| import java.util.Map; | ||
|
|
||
| public interface ExpressionTranslator<T> |
There was a problem hiding this comment.
We should build something like RowExpressionRewriter and RowExpressionTreeRewriter to as a helper
|
|
||
| import static com.facebook.presto.translator.registry.ScalarFromAnnotationsParser.removeTypeParameters; | ||
|
|
||
| public class ConstantTypeRegistry |
|
|
||
| import static com.facebook.presto.translator.registry.ScalarFromAnnotationsParser.parseFunctionDefinitions; | ||
|
|
||
| public class FunctionRegistry |
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public class TargetExpression<T> |
There was a problem hiding this comment.
Let's put this together with optimizer interface.
|
#13491 continue work here. |
A bare bones mocked implementation of how the interface for row expression translation in the connector may look like.
Details are still being finalized, we may/may not agree to do it this way. Read my review comments for any details on what this is supposed to be doing.