Repository: phoenix
Updated Branches:
  refs/heads/calcite 4a3b80fa8 -> 483de89a7


PHOENIX-3700 Implement getConnectioInfo methods in 
PhoenixCalciteConnection(Rajeshbabu)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/483de89a
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/483de89a
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/483de89a

Branch: refs/heads/calcite
Commit: 483de89a7dd0cd5e6e17df0631bb68b6bfa2221d
Parents: 4a3b80f
Author: Rajeshbabu Chintaguntla <[email protected]>
Authored: Tue Feb 28 15:49:15 2017 +0530
Committer: Rajeshbabu Chintaguntla <[email protected]>
Committed: Tue Feb 28 15:49:15 2017 +0530

----------------------------------------------------------------------
 .../calcite/jdbc/PhoenixCalciteFactory.java     | 31 ++++++++++++++++++--
 .../apache/phoenix/calcite/CalciteUtils.java    | 13 ++++++++
 .../apache/phoenix/calcite/PhoenixSchema.java   | 15 +++++++++-
 3 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/483de89a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java 
b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
index 15d8b83..92ad86a 100644
--- 
a/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
+++ 
b/phoenix-core/src/main/java/org/apache/calcite/jdbc/PhoenixCalciteFactory.java
@@ -297,17 +297,42 @@ public class PhoenixCalciteFactory extends CalciteFactory 
{
 
         @Override
         public DatabaseMetaData getMetaData() throws SQLException {
+            PhoenixConnection pc = getPhoenixConnection(getRootSchema());
+            if(pc != null) {
+                return pc.getMetaData();
+            }
+            return super.getMetaData();
+        }
+
+        @Override
+        public Properties getClientInfo() throws SQLException {
+            PhoenixConnection pc = getPhoenixConnection(getRootSchema());
+            if(pc != null) {
+                return pc.getClientInfo();
+            }
+            return super.getClientInfo();
+        }
+
+        @Override
+        public String getClientInfo(String name) throws SQLException {
+            PhoenixConnection pc = getPhoenixConnection(getRootSchema());
+            if(pc != null) {
+                return pc.getClientInfo(name);
+            }
+            return super.getClientInfo(name);
+        }
+        
+        private PhoenixConnection getPhoenixConnection(SchemaPlus rootSchema) {
             for (String subSchemaName : getRootSchema().getSubSchemaNames()) {
                 try {
                     PhoenixSchema phoenixSchema =
                             
getRootSchema().getSubSchema(subSchemaName).unwrap(PhoenixSchema.class);
-                    return phoenixSchema.pc.getMetaData();
+                    return phoenixSchema.pc;
                 } catch (ClassCastException e) {
                 }
             }
-            return super.getMetaData();
+            return null;
         }
-
         @SuppressWarnings("unchecked")
         @Override
         public <T> T unwrap(Class<T> iface) throws SQLException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/483de89a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index 1b6937b..b49ca28 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -908,6 +908,19 @@ public class CalciteUtils {
                         return new CoalesceFunction(children);
                     } else if (op == SqlStdOperatorTable.MOD) {
                         return new ModulusExpression(children);
+                    } else if (op == SqlStdOperatorTable.CAST) {
+                        PDataType targetType = 
relDataTypeToPDataType(node.getType());
+                        Integer maxLength =
+                                (targetType == PChar.INSTANCE
+                                    || targetType == PCharArray.INSTANCE
+                                    || targetType == PBinary.INSTANCE
+                                    || targetType == PBinaryArray.INSTANCE) ?
+                                node.getType().getPrecision() : null;
+                        try {
+                            return cast(targetType, maxLength, 
children.get(0), implementor);
+                        } catch (SQLException e) {
+                            throw new RuntimeException(e);
+                        }
                     };
                 } catch (SQLException e) {
                     throw new RuntimeException(e);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/483de89a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index d88f226..63f72a2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -185,7 +185,10 @@ public class PhoenixSchema implements Schema {
                 if(ignoredRegexFunctions.contains(info.getFunc().getName())){
                     continue;
                 }
-                builtinFunctions.putAll(info.getName(), 
convertBuiltinFunction(info));
+                List<PhoenixScalarFunction> convertBuiltinFunction = 
convertBuiltinFunction(info);
+                if(convertBuiltinFunction!=null) {
+                    builtinFunctions.putAll(info.getName(), 
convertBuiltinFunction);
+                }
             }
         }
         // Single depth alias functions only
@@ -213,6 +216,16 @@ public class PhoenixSchema implements Schema {
         Class<? extends FunctionExpression> clazz = functionInfo.getFunc();
 
         try {
+            if(overloadedArgs.isEmpty()) {
+                PDataType returnType = null;
+                try{
+                    returnType = evaluateReturnType(clazz, new 
ArrayList<PFunction.FunctionArgument>(1));
+                } catch(Exception e) {
+                    return null;
+                }
+                functionList.add(new PhoenixScalarFunction(functionInfo, new 
ArrayList<FunctionParameter>(1), returnType));
+                return functionList;
+            }
             for (List<FunctionArgument> argumentList : overloadedArgs) {
                 List<FunctionParameter> parameters = 
Lists.newArrayListWithExpectedSize(argumentList.size());
                 PDataType returnType = evaluateReturnType(clazz, argumentList);

Reply via email to