You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/07/02 23:01:49 UTC
[46/47] phoenix git commit: PHOENIX-2011 Default, min,
and max values should not require quotes around it in create
function(Rajeshbabu)
PHOENIX-2011 Default, min, and max values should not require quotes around it in create function(Rajeshbabu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b2fb04b0
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b2fb04b0
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b2fb04b0
Branch: refs/heads/calcite
Commit: b2fb04b0c2234c5b573642d39589ab9d36469723
Parents: 54da7d1
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Thu Jul 2 15:51:18 2015 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Thu Jul 2 15:51:18 2015 +0530
----------------------------------------------------------------------
.../apache/phoenix/end2end/UserDefinedFunctionsIT.java | 12 ++++++------
phoenix-core/src/main/antlr3/PhoenixSQL.g | 3 ++-
.../phoenix/coprocessor/MetaDataEndpointImpl.java | 9 +++++----
.../org/apache/phoenix/parse/FunctionParseNode.java | 9 +++------
.../main/java/org/apache/phoenix/parse/PFunction.java | 12 +++++++++---
.../java/org/apache/phoenix/schema/MetaDataClient.java | 6 +++---
6 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java
index cee1c85..613231d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java
@@ -348,7 +348,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
}
- tenant2Conn.createStatement().execute("create function myfunction(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ tenant2Conn.createStatement().execute("create function myfunction(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
try {
tenant2Conn.createStatement().execute("create function myfunction(VARCHAR) returns VARCHAR as 'org.apache.phoenix.end2end.UnknownClass' using jar "
@@ -424,7 +424,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
conn.commit();
conn.createStatement().execute("create table t2(k integer primary key, k1 integer, lastname_reverse varchar)");
conn.commit();
- stmt.execute("create function mysum3(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ stmt.execute("create function mysum3(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
stmt.execute("create function myreverse3(VARCHAR) returns VARCHAR as 'org.apache.phoenix.end2end."+MY_REVERSE_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar1.jar"+"'");
@@ -458,7 +458,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
conn.createStatement().execute("create table t4(k integer primary key, k1 integer, lastname varchar)");
stmt.execute("upsert into t4 values(1,1,'jock')");
conn.commit();
- stmt.execute("create function mysum(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ stmt.execute("create function mysum(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
ResultSet rs = stmt.executeQuery("select mysum(k,12) from t4");
assertTrue(rs.next());
@@ -481,7 +481,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
conn.createStatement().execute("create table t9(k integer primary key, k1 integer, lastname varchar)");
stmt.execute("upsert into t9 values(1,1,'jock')");
conn.commit();
- stmt.execute("create temporary function mysum9(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ stmt.execute("create temporary function mysum9(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
ResultSet rs = stmt.executeQuery("select mysum9(k,12) from t9");
assertTrue(rs.next());
@@ -523,7 +523,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
ResultSet rs = stmt.executeQuery(query);
rs.next();
int numRowsBefore = rs.getInt(1);
- stmt.execute("create function mysum6(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ stmt.execute("create function mysum6(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
rs = stmt.executeQuery(query);
rs.next();
@@ -551,7 +551,7 @@ public class UserDefinedFunctionsIT extends BaseOwnClusterIT{
} catch(FunctionNotFoundException e) {
fail("FunctionNotFoundException should not be thrown");
}
- stmt.execute("create function mysum6(INTEGER, INTEGER CONSTANT defaultValue='10' minvalue='1' maxvalue='15' ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ stmt.execute("create function mysum6(INTEGER, INTEGER CONSTANT defaultValue=10 minvalue=1 maxvalue=15 ) returns INTEGER as 'org.apache.phoenix.end2end."+MY_SUM_CLASS_NAME+"' using jar "
+ "'"+util.getConfiguration().get(DYNAMIC_JARS_DIR_KEY) + "/myjar2.jar"+"'");
try {
rs = stmt.executeQuery("select mysum6(k1) from t6");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index 4f7cb34..2a8d11b 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -921,12 +921,13 @@ zero_or_more_data_types returns [List<FunctionArgument> ret]
;
function_argument returns [FunctionArgument ret]
- : (dt = identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)? (c = CONSTANT)? (DEFAULTVALUE EQ dv = value_expression)? (MINVALUE EQ minv = value_expression)? (MAXVALUE EQ maxv = value_expression)?
+ : (dt = identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)? (c = CONSTANT)? (DEFAULTVALUE EQ dv = expression)? (MINVALUE EQ minv = expression)? (MAXVALUE EQ maxv = expression)?
{ $ret = new FunctionArgument(dt, ar != null || lsq != null, c!=null,
dv == null ? null : LiteralExpression.newConstant(((LiteralParseNode)dv).getValue()),
minv == null ? null : LiteralExpression.newConstant(((LiteralParseNode)minv).getValue()),
maxv == null ? null : LiteralExpression.newConstant(((LiteralParseNode)maxv).getValue()));})
;
+
value_expression_list returns [List<ParseNode> ret]
@init{ret = new ArrayList<ParseNode>(); }
: LPAREN e = value_expression {$ret.add(e);} (COMMA e = value_expression {$ret.add(e);} )* RPAREN
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index dc1a3b4..1fc1d7f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -138,6 +138,7 @@ import org.apache.phoenix.index.IndexMaintainer;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.metrics.Metrics;
+import org.apache.phoenix.parse.LiteralParseNode;
import org.apache.phoenix.parse.PFunction;
import org.apache.phoenix.parse.PFunction.FunctionArgument;
import org.apache.phoenix.protobuf.ProtobufUtil;
@@ -598,7 +599,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
}
private void addArgumentToFunction(List<Cell> results, PName functionName, PName type,
- Cell[] functionKeyValues, List<FunctionArgument> arguments, short argPosition) {
+ Cell[] functionKeyValues, List<FunctionArgument> arguments, short argPosition) throws SQLException {
int i = 0;
int j = 0;
while (i < results.size() && j < FUNCTION_ARG_KV_COLUMNS.size()) {
@@ -645,9 +646,9 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
maxValueKv.getValueLength());
FunctionArgument arg =
new FunctionArgument(type.getString(), isArrayType, isConstant,
- defaultValue == null ? null : LiteralExpression.newConstant(defaultValue),
- minValue == null ? null : LiteralExpression.newConstant(minValue),
- maxValue == null ? null : LiteralExpression.newConstant(maxValue),
+ defaultValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(defaultValue)).getValue()),
+ minValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(minValue)).getValue()),
+ maxValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(maxValue)).getValue()),
argPosition);
arguments.add(arg);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
index be52d89..0dd021b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
@@ -419,14 +419,11 @@ public class FunctionParseNode extends CompoundParseNode {
this.allowedTypes = new Class[] { dataType.getClass() };
this.isConstant = arg.isConstant();
this.defaultValue =
- arg.getDefaultValue() == null ? null : getExpFromConstant((String) arg
- .getDefaultValue().getValue());
+ arg.getDefaultValue() == null ? null : arg.getDefaultValue();
this.minValue =
- arg.getMinValue() == null ? null : getExpFromConstant((String) arg
- .getMinValue().getValue());
+ arg.getMinValue() == null ? null : arg.getMinValue();
this.maxValue =
- arg.getMaxValue() == null ? null : getExpFromConstant((String) arg
- .getMaxValue().getValue());
+ arg.getMaxValue() == null ? null : arg.getMaxValue();
}
private LiteralExpression getExpFromConstant(String strValue) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java
index 8a95ae7..a1413de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/PFunction.java
@@ -30,6 +30,8 @@ import org.apache.phoenix.schema.PMetaDataEntity;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PNameFactory;
import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.SizedUtil;
public class PFunction implements PMetaDataEntity {
@@ -233,14 +235,18 @@ public class PFunction implements PMetaDataEntity {
for(PFunctionArg arg: function.getArgumentsList()) {
String argType = arg.getArgumentType();
boolean isArrayType = arg.hasIsArrayType()?arg.getIsArrayType():false;
+ PDataType dataType = isArrayType ? PDataType.fromTypeId(PDataType
+ .sqlArrayType(SchemaUtil.normalizeIdentifier(SchemaUtil
+ .normalizeIdentifier(argType)))) : PDataType
+ .fromSqlTypeName(SchemaUtil.normalizeIdentifier(argType));
boolean isConstant = arg.hasIsConstant()?arg.getIsConstant():false;
String defaultValue = arg.hasDefaultValue()?arg.getDefaultValue():null;
String minValue = arg.hasMinValue()?arg.getMinValue():null;
String maxValue = arg.hasMaxValue()?arg.getMaxValue():null;
args.add(new FunctionArgument(argType, isArrayType, isConstant,
- defaultValue == null ? null : LiteralExpression.newConstant(defaultValue),
- minValue == null ? null : LiteralExpression.newConstant(minValue),
- maxValue == null ? null : LiteralExpression.newConstant(maxValue)));
+ defaultValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(defaultValue))).getValue()),
+ minValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(minValue))).getValue()),
+ maxValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(maxValue))).getValue())));
}
return new PFunction(tenantId,functionName, args, returnType, className, jarPath, timeStamp);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2fb04b0/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 0ad9b56..f24da44 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -680,9 +680,9 @@ public class MetaDataClient {
argUpsert.setBytes(4, bytes);
argUpsert.setBoolean(5, arg.isArrayType());
argUpsert.setBoolean(6, arg.isConstant());
- argUpsert.setString(7, arg.getDefaultValue() == null? null: (String)arg.getDefaultValue().getValue());
- argUpsert.setString(8, arg.getMinValue() == null? null: (String)arg.getMinValue().getValue());
- argUpsert.setString(9, arg.getMaxValue() == null? null: (String)arg.getMaxValue().getValue());
+ argUpsert.setString(7, arg.getDefaultValue() == null? null: arg.getDefaultValue().toString());
+ argUpsert.setString(8, arg.getMinValue() == null? null: arg.getMinValue().toString());
+ argUpsert.setString(9, arg.getMaxValue() == null? null: arg.getMaxValue().toString());
argUpsert.execute();
}