Repository: phoenix
Updated Branches:
  refs/heads/master f7c1889bc -> d23ebef21


Phoenix-952 Support ANY and ALL built-ins for ARRAYs - Adding new files


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

Branch: refs/heads/master
Commit: d23ebef2148eef5843e5e5331d556f0ffe260900
Parents: f7c1889
Author: Ramkrishna <ramkrishna.s.vasude...@intel.com>
Authored: Fri Jul 4 11:21:36 2014 +0530
Committer: Ramkrishna <ramkrishna.s.vasude...@intel.com>
Committed: Fri Jul 4 11:21:36 2014 +0530

----------------------------------------------------------------------
 .../function/ArrayAllComparisonExpression.java  | 45 +++++++++++
 .../function/ArrayAnyComparisonExpression.java  | 78 ++++++++++++++++++++
 .../function/InlineArrayElemRefExpression.java  | 73 ++++++++++++++++++
 .../phoenix/parse/ArrayAllComparisonNode.java   | 46 ++++++++++++
 .../phoenix/parse/ArrayAnyComparisonNode.java   | 46 ++++++++++++
 .../apache/phoenix/parse/ArrayElemRefNode.java  | 38 ++++++++++
 6 files changed, 326 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
new file mode 100644
index 0000000..9acdadb
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.schema.PDataType;
+
+public class ArrayAllComparisonExpression extends ArrayAnyComparisonExpression 
{
+
+    public ArrayAllComparisonExpression() {}
+
+    public ArrayAllComparisonExpression(List<Expression> children) {
+        super(children);
+    }
+
+    @Override
+    protected boolean resultFound(ImmutableBytesWritable ptr) {
+        if (Bytes.equals(ptr.get(), PDataType.FALSE_BYTES)) { return true; }
+        return false;
+    }
+
+    @Override
+    protected boolean result() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
new file mode 100644
index 0000000..dd85bb7
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.BaseCompoundExpression;
+import org.apache.phoenix.expression.ComparisonExpression;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.schema.PArrayDataType;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+public class ArrayAnyComparisonExpression extends BaseCompoundExpression {
+    public ArrayAnyComparisonExpression () {
+    }
+    public ArrayAnyComparisonExpression(List<Expression> children) {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression arrayKVExpression = children.get(0);
+        if (!arrayKVExpression.evaluate(tuple, ptr)) {
+            return false;
+        } else if (ptr.getLength() == 0) { return true; }
+        int length = PArrayDataType.getArrayLength(ptr,
+                
PDataType.fromTypeId(children.get(0).getDataType().getSqlType() - 
PDataType.ARRAY_TYPE_BASE),
+                arrayKVExpression.getMaxLength());
+        boolean elementAvailable = false;
+        for (int i = 0; i < length; i++) {
+            Expression comparisonExpr = children.get(1);
+            Expression arrayElemRef = 
((ComparisonExpression)comparisonExpr).getChildren().get(1);
+            ((InlineArrayElemRefExpression)arrayElemRef).setIndex(i + 1);
+            comparisonExpr.evaluate(tuple, ptr);
+            if (expectedReturnResult(resultFound(ptr))) { return result(); }
+            elementAvailable = true;
+        }
+        if (!elementAvailable) { return false; }
+        return true;
+    }
+    protected boolean resultFound(ImmutableBytesWritable ptr) {
+        if(Bytes.equals(ptr.get(), PDataType.TRUE_BYTES)) {
+            return true;
+        }
+        return false;
+    }
+    
+    protected boolean result() {
+        return true;
+    }
+    
+    protected boolean expectedReturnResult(boolean result) {
+        return true == result;
+    }
+
+    @Override
+    public PDataType getDataType() {
+        return PDataType.BOOLEAN;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
new file mode 100644
index 0000000..9082911
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.expression.function;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.BaseCompoundExpression;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.schema.PArrayDataType;
+import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+public class InlineArrayElemRefExpression extends BaseCompoundExpression {
+
+    private int index;
+
+    public InlineArrayElemRefExpression() {
+    }
+    
+    public InlineArrayElemRefExpression(List<Expression> children) {
+        super(children);
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression arrayExpr = children.get(0);
+        return PArrayDataType.positionAtArrayElement(tuple, ptr, index, 
arrayExpr, getDataType(), getMaxLength());
+    }
+
+    @Override
+    public Integer getMaxLength() {
+        return this.children.get(0).getMaxLength();
+    }
+
+    @Override
+    public PDataType getDataType() {
+        return PDataType.fromTypeId(children.get(0).getDataType().getSqlType() 
- PDataType.ARRAY_TYPE_BASE);
+    }
+    
+    @Override
+    public void write(DataOutput output) throws IOException {
+        super.write(output);
+    }
+    
+    @Override
+    public void readFields(DataInput input) throws IOException {
+        super.readFields(input);
+    }
+    
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAllComparisonNode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAllComparisonNode.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAllComparisonNode.java
new file mode 100644
index 0000000..b31b3ae
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAllComparisonNode.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.parse;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+/** 
+ * The Expression a = ALL(b) where b is of type array is rewritten in this
+ * node as ALL(a = b(n))
+ */
+public class ArrayAllComparisonNode extends CompoundParseNode {
+
+    ArrayAllComparisonNode(ParseNode rhs, ComparisonParseNode compareNode) {
+        super(Arrays.<ParseNode>asList(rhs, compareNode));
+    }
+    
+    public String getType() {
+        return "ALL";
+    }
+
+    @Override
+    public <T> T accept(ParseNodeVisitor<T> visitor) throws SQLException {
+        List<T> l = Collections.emptyList();
+        if (visitor.visitEnter(this)) {
+            l = acceptChildren(visitor);
+        }
+        return visitor.visitLeave(this, l);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAnyComparisonNode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAnyComparisonNode.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAnyComparisonNode.java
new file mode 100644
index 0000000..daca86d
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayAnyComparisonNode.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.parse;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+/** 
+ * The Expression a = ANY(b) where b is of type array is rewritten in this
+ * node as ANY(a = b(n))
+ */
+public class ArrayAnyComparisonNode extends CompoundParseNode {
+
+    ArrayAnyComparisonNode(ParseNode rhs, ComparisonParseNode compareNode) {
+        super(Arrays.<ParseNode>asList(rhs, compareNode));
+    }
+    
+    public String getType() {
+        return "ANY";
+    }
+
+    @Override
+    public <T> T accept(ParseNodeVisitor<T> visitor) throws SQLException {
+        List<T> l = Collections.emptyList();
+        if (visitor.visitEnter(this)) {
+            l = acceptChildren(visitor);
+        }
+        return visitor.visitLeave(this, l);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d23ebef2/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayElemRefNode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayElemRefNode.java 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayElemRefNode.java
new file mode 100644
index 0000000..da69de2
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ArrayElemRefNode.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.parse;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+
+public class ArrayElemRefNode extends CompoundParseNode {
+
+    public ArrayElemRefNode(List<ParseNode> parseNode) {
+        super(parseNode);
+    }
+
+    @Override
+    public <T> T accept(ParseNodeVisitor<T> visitor) throws SQLException {
+        List<T> l = Collections.emptyList();
+        if (visitor.visitEnter(this)) {
+            l = acceptChildren(visitor);
+        }
+        return visitor.visitLeave(this, l);
+    }
+}

Reply via email to