You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sa...@apache.org on 2016/11/04 22:13:42 UTC
[15/50] [abbrv] phoenix git commit: PHOENIX-3417 Refactor function
argument validation with function argument info to separate
method(Rajeshbabu)
PHOENIX-3417 Refactor function argument validation with function argument info to separate method(Rajeshbabu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/87266ef0
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/87266ef0
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/87266ef0
Branch: refs/heads/encodecolumns2
Commit: 87266ef07f070129a7dcefe7f214b9e8b07dbf56
Parents: fc3af30
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Fri Oct 28 12:29:49 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Fri Oct 28 12:29:49 2016 +0530
----------------------------------------------------------------------
.../apache/phoenix/parse/FunctionParseNode.java | 73 +++++++++++---------
1 file changed, 40 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/87266ef0/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 0dd021b..952d0d3 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
@@ -186,44 +186,51 @@ public class FunctionParseNode extends CompoundParseNode {
}
}
} else {
- if (allowedTypes.length > 0) {
- boolean isCoercible = false;
- for (Class<? extends PDataType> type : allowedTypes) {
- if (child.getDataType().isCoercibleTo(
- PDataTypeFactory.getInstance().instanceFromClass(type))) {
- isCoercible = true;
- break;
- }
- }
- if (!isCoercible) {
- throw new ArgumentTypeMismatchException(args[i].getAllowedTypes(),
- child.getDataType(), info.getName() + " argument " + (i + 1));
- }
- if (child instanceof LiteralExpression) {
- LiteralExpression valueExp = (LiteralExpression) child;
- LiteralExpression minValue = args[i].getMinValue();
- LiteralExpression maxValue = args[i].getMaxValue();
- if (minValue != null && minValue.getDataType().compareTo(minValue.getValue(), valueExp.getValue(), valueExp.getDataType()) > 0) {
- throw new ValueRangeExcpetion(minValue, maxValue == null ? "" : maxValue, valueExp.getValue(), info.getName() + " argument " + (i + 1));
- }
- if (maxValue != null && maxValue.getDataType().compareTo(maxValue.getValue(), valueExp.getValue(), valueExp.getDataType()) < 0) {
- throw new ValueRangeExcpetion(minValue == null ? "" : minValue, maxValue, valueExp.getValue(), info.getName() + " argument " + (i + 1));
- }
- }
+ validateFunctionArguement(info, i, child);
+ }
+ }
+ return children;
+ }
+
+ public static void validateFunctionArguement(BuiltInFunctionInfo info,
+ int childIndex, Expression child)
+ throws ArgumentTypeMismatchException, ValueRangeExcpetion {
+ BuiltInFunctionArgInfo arg = info.getArgs()[childIndex];
+ if (arg.getAllowedTypes().length > 0) {
+ boolean isCoercible = false;
+ for (Class<? extends PDataType> type :arg.getAllowedTypes()) {
+ if (child.getDataType().isCoercibleTo(
+ PDataTypeFactory.getInstance().instanceFromClass(type))) {
+ isCoercible = true;
+ break;
}
- if (args[i].isConstant() && ! (child instanceof LiteralExpression) ) {
- throw new ArgumentTypeMismatchException("constant", child.toString(), info.getName() + " argument " + (i + 1));
+ }
+ if (!isCoercible) {
+ throw new ArgumentTypeMismatchException(arg.getAllowedTypes(),
+ child.getDataType(), info.getName() + " argument " + (childIndex + 1));
+ }
+ if (child instanceof LiteralExpression) {
+ LiteralExpression valueExp = (LiteralExpression) child;
+ LiteralExpression minValue = arg.getMinValue();
+ LiteralExpression maxValue = arg.getMaxValue();
+ if (minValue != null && minValue.getDataType().compareTo(minValue.getValue(), valueExp.getValue(), valueExp.getDataType()) > 0) {
+ throw new ValueRangeExcpetion(minValue, maxValue == null ? "" : maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1));
}
- if (!args[i].getAllowedValues().isEmpty()) {
- Object value = ((LiteralExpression)child).getValue();
- if (!args[i].getAllowedValues().contains(value.toString().toUpperCase())) {
- throw new ArgumentTypeMismatchException(Arrays.toString(args[i].getAllowedValues().toArray(new String[0])),
- value.toString(), info.getName() + " argument " + (i + 1));
- }
+ if (maxValue != null && maxValue.getDataType().compareTo(maxValue.getValue(), valueExp.getValue(), valueExp.getDataType()) < 0) {
+ throw new ValueRangeExcpetion(minValue == null ? "" : minValue, maxValue, valueExp.getValue(), info.getName() + " argument " + (childIndex + 1));
}
}
}
- return children;
+ if (arg.isConstant() && ! (child instanceof LiteralExpression) ) {
+ throw new ArgumentTypeMismatchException("constant", child.toString(), info.getName() + " argument " + (childIndex + 1));
+ }
+ if (!arg.getAllowedValues().isEmpty()) {
+ Object value = ((LiteralExpression)child).getValue();
+ if (!arg.getAllowedValues().contains(value.toString().toUpperCase())) {
+ throw new ArgumentTypeMismatchException(Arrays.toString(arg.getAllowedValues().toArray(new String[0])),
+ value.toString(), info.getName() + " argument " + (childIndex + 1));
+ }
+ }
}
/**