public RowFieldReference(RowType type, Type returnType, int index, String fieldName) { super(mangleFieldReference(fieldName), ImmutableList.of(), returnType.getTypeSignature().toString(), ImmutableList.of(type.getTypeSignature().toString())); String stackType = returnType.getJavaType().getSimpleName().toLowerCase(); MethodHandle methodHandle; if (METHOD_HANDLE_MAP.containsKey(stackType)) { methodHandle = METHOD_HANDLE_MAP.get(stackType); } else { methodHandle = METHOD_HANDLE_OBJECT; } this.methodHandle = methodHandle.bindTo(returnType).bindTo(index); }
@Override public Expression rewriteDereferenceExpression(DereferenceExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { if (analysis.getFieldIndex(node).isPresent()) { return rewriteExpressionWithResolvedName(node); } // Rewrite all row field reference to function call. QualifiedName mangledName = QualifiedName.of(mangleFieldReference(node.getFieldName())); FunctionCall functionCall = new FunctionCall(mangledName, ImmutableList.of(node.getBase())); // hackish - add type for created node to analysis object so further rewriting does not fail IdentityHashMap<Expression, Type> functionType = new IdentityHashMap<>(); functionType.put(functionCall, analysis.getType(node)); analysis.addTypes(functionType); Expression rewrittenExpression = rewriteFunctionCall(functionCall, context, treeRewriter); // cast expression if coercion is registered Type type = analysis.getType(node); Type coercion = analysis.getCoercion(node); if (coercion != null) { rewrittenExpression = new Cast( rewrittenExpression, coercion.getTypeSignature().toString(), false, isTypeOnlyCoercion(type.getTypeSignature(), coercion.getTypeSignature())); } return rewrittenExpression; } }, expression);
@Override public Expression rewriteDereferenceExpression(DereferenceExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { if (analysis.getColumnReferences().contains(node)) { return rewriteExpression(node, context, treeRewriter); } // Rewrite all row field reference to function call. QualifiedName mangledName = QualifiedName.of(mangleFieldReference(node.getFieldName())); FunctionCall functionCall = new FunctionCall(mangledName, ImmutableList.of(node.getBase())); Expression rewrittenExpression = rewriteFunctionCall(functionCall, context, treeRewriter); // cast expression if coercion is registered Type coercion = analysis.getCoercion(node); if (coercion != null) { rewrittenExpression = new Cast(rewrittenExpression, coercion.getTypeSignature().toString()); } return rewrittenExpression; } }, parsedExpression);