GitHub PullRequestReviewCommentEvent at 2014-04-10 02:08:22
Repository: presto
Actor: erichwang
Payload: {"comment":{"url":"https://api.github.com/repos/facebook/presto/pulls/comments/11467459","id":11467459,"diff_hunk":"@@ -602,36 +639,202 @@ protected Type visitExpression(Expression node, AnalysisContext context)\n         {\n             throw new UnsupportedOperationException(\"not yet implemented: \" + node.getClass().getName());\n         }\n-    }\n \n-    public static Predicate<Type> sameTypePredicate(final Type type)\n-    {\n-        return new Predicate<Type>()\n+        private Type getOperator(AnalysisContext context, Expression node, OperatorType operatorType, Expression... arguments)\n+        {\n+            ImmutableList.Builder<Type> argumentTypes = ImmutableList.builder();\n+            for (Expression expression : arguments) {\n+                argumentTypes.add(process(expression, context));\n+            }\n+\n+            OperatorInfo operatorInfo;\n+            try {\n+                operatorInfo = metadata.resolveOperator(operatorType, argumentTypes.build());\n+            }\n+            catch (IllegalArgumentException e) {\n+                // todo not correct\n+                throw new SemanticException(TYPE_MISMATCH, node, e.getMessage());\n+            }\n+\n+            for (int i = 0; i < arguments.length; i++) {\n+                Expression expression = arguments[i];\n+                Type type = operatorInfo.getArgumentTypes().get(i);\n+                checkType(context, expression, type, String.format(\"Operator %s argument %d\", operatorInfo, i));\n+            }\n+            resolvedOperators.put(node, operatorInfo);\n+\n+            expressionTypes.put(node, operatorInfo.getReturnType());\n+\n+            return operatorInfo.getReturnType();\n+        }\n+\n+        private Type checkType(AnalysisContext context, Expression expression, Type expectedType, String message)\n         {\n-            public boolean apply(Type input)\n-            {\n-                return sameType(type, input);\n+            Type actualType = process(expression, context);\n+            if (!actualType.equals(expectedType)) {\n+                if (!FunctionRegistry.canCoerce(actualType, expectedType)) {\n+                    throw new SemanticException(TYPE_MISMATCH, expression, message + \" must evaluate to a %s (actual: %s)\", expectedType, actualType);\n+                }\n+                expressionCoercions.put(expression, expectedType);\n             }\n-        };\n+            return actualType;\n+        }\n+\n+        private Type checkSameType(AnalysisContext context, Node node, String message, Expression first, Expression second)","path":"presto-main/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java","position":839,"original_position":839,"commit_id":"0e6e22f71fb1bf6069c9f75b44d1594a104b1b07","original_commit_id":"0e6e22f71fb1bf6069c9f75b44d1594a104b1b07","user":{"login":"erichwang","id":737851,"avatar_url":"https://avatars.githubusercontent.com/u/737851?","gravatar_id":"faf04ea3c36273067804c43b736e7a4c","url":"https://api.github.com/users/erichwang","html_url":"https://github.com/erichwang","followers_url":"https://api.github.com/users/erichwang/followers","following_url":"https://api.github.com/users/erichwang/following{/other_user}","gists_url":"https://api.github.com/users/erichwang/gists{/gist_id}","starred_url":"https://api.github.com/users/erichwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erichwang/subscriptions","organizations_url":"https://api.github.com/users/erichwang/orgs","repos_url":"https://api.github.com/users/erichwang/repos","events_url":"https://api.github.com/users/erichwang/events{/privacy}","received_events_url":"https://api.github.com/users/erichwang/received_events","type":"User","site_admin":false},"body":"coerceToSingleType","created_at":"2014-04-10T02:08:22Z","updated_at":"2014-04-10T02:08:22Z","html_url":"https://github.com/facebook/presto/pull/1186#discussion_r11467459","pull_request_url":"https://api.github.com/repos/facebook/presto/pulls/1186","_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments/11467459"},"html":{"href":"https://github.com/facebook/presto/pull/1186#discussion_r11467459"},"pull_request":{"href":"https://api.github.com/repos/facebook/presto/pulls/1186"}}}}