Repository: vxquery
Updated Branches:
  refs/heads/master f79a1218a -> 4a6f2aa67 (forced update)


VXQUERY-215 Left operand of a pair is ExprSingle


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

Branch: refs/heads/master
Commit: ba6af98808648fec9267860e31034cec13772cc5
Parents: 9f458dc
Author: riyafa <[email protected]>
Authored: Wed Jun 29 20:23:44 2016 +0530
Committer: riyafa <[email protected]>
Committed: Fri Jul 1 12:52:24 2016 +0530

----------------------------------------------------------------------
 .../vxquery/xmlquery/ast/PairConstructor.java   |  6 +-
 .../xmlquery/translator/XMLQueryTranslator.java | 58 ++++++++++----------
 vxquery-core/src/main/javacc/xquery-grammar.jj  |  9 +--
 .../Json/Object/q09_object.txt                  |  1 +
 .../Json/Object/q10_object.txt                  |  1 +
 .../Queries/XQuery/Json/Object/q07_object.xq    |  2 +-
 .../Queries/XQuery/Json/Object/q08_object.xq    | 22 ++++++++
 .../Queries/XQuery/Json/Object/q09_object.xq    | 22 ++++++++
 .../Queries/XQuery/Json/Object/q10_object.xq    | 24 ++++++++
 .../Queries/XQuery/Json/Object/q11_object.xq    | 23 ++++++++
 .../test/resources/cat/JsonObjectQueries.xml    | 20 +++++++
 11 files changed, 150 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/PairConstructor.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/PairConstructor.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/PairConstructor.java
index 082802b..add12ad 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/PairConstructor.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/PairConstructor.java
@@ -19,7 +19,7 @@ package org.apache.vxquery.xmlquery.ast;
 import org.apache.vxquery.util.SourceLocation;
 
 public class PairConstructor extends ASTNode{
-    private String key;
+    private ASTNode key;
     private ASTNode value;
     public PairConstructor(SourceLocation loc) {
         super(loc);
@@ -30,11 +30,11 @@ public class PairConstructor extends ASTNode{
         return ASTTag.PAIR_CONSTRUCTOR;
     }
 
-    public String getKey() {
+    public ASTNode getKey() {
         return key;
     }
 
-    public void setKey(String key) {
+    public void setKey(ASTNode key) {
         this.key = key;
     }
 

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
index 8ae5828..08da24c 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
@@ -767,35 +767,35 @@ public class XMLQueryTranslator {
                 return translateQuantifiedExprNode(tCtx, qeNode);
             }
 
-                /*
-                        case TYPESWITCH_EXPRESSION: {
-                            TypeswitchExprNode teNode = (TypeswitchExprNode) 
value;
-                            Expression sExpr = 
translateExpression(teNode.getSwitchExpr());
-                            ForLetVariable tVar = new 
ForLetVariable(VarTag.LET, createVarName(), sExpr);
-                            
tVar.setDeclaredStaticType(SequenceType.create(AnyItemType.INSTANCE, 
Quantifier.QUANT_STAR));
+            /*
+                    case TYPESWITCH_EXPRESSION: {
+                        TypeswitchExprNode teNode = (TypeswitchExprNode) value;
+                        Expression sExpr = 
translateExpression(teNode.getSwitchExpr());
+                        ForLetVariable tVar = new ForLetVariable(VarTag.LET, 
createVarName(), sExpr);
+                        
tVar.setDeclaredStaticType(SequenceType.create(AnyItemType.INSTANCE, 
Quantifier.QUANT_STAR));
+                        pushVariableScope();
+                        varScope.registerVariable(tVar);
+                        List<TypeswitchExpression.Case> cases = new 
ArrayList<TypeswitchExpression.Case>();
+                        for (CaseClauseNode ccNode : teNode.getCaseClauses()) {
+                            SequenceType type = 
createSequenceType(ccNode.getType());
+                            ForLetVariable caseVar = null;
                             pushVariableScope();
-                            varScope.registerVariable(tVar);
-                            List<TypeswitchExpression.Case> cases = new 
ArrayList<TypeswitchExpression.Case>();
-                            for (CaseClauseNode ccNode : 
teNode.getCaseClauses()) {
-                                SequenceType type = 
createSequenceType(ccNode.getType());
-                                ForLetVariable caseVar = null;
-                                pushVariableScope();
-                                if (ccNode.getCaseVar() != null) {
-                                    caseVar = new ForLetVariable(VarTag.LET, 
createQName(ccNode.getCaseVar()), new TreatExpression(
-                                            currCtx, new 
VariableReferenceExpression(currCtx, tVar), type));
-                                    caseVar.setDeclaredStaticType(type);
-                                    varScope.registerVariable(caseVar);
-                                }
-                                Expression cExpr = 
translateExpression(ccNode.getValueExpr());
-                                TypeswitchExpression.Case c = new 
TypeswitchExpression.Case(caseVar, type, cExpr);
-                                cases.add(c);
-                                popVariableScope();
+                            if (ccNode.getCaseVar() != null) {
+                                caseVar = new ForLetVariable(VarTag.LET, 
createQName(ccNode.getCaseVar()), new TreatExpression(
+                                        currCtx, new 
VariableReferenceExpression(currCtx, tVar), type));
+                                caseVar.setDeclaredStaticType(type);
+                                varScope.registerVariable(caseVar);
                             }
-                            Expression dExpr = 
translateExpression(teNode.getDefaultClause());
+                            Expression cExpr = 
translateExpression(ccNode.getValueExpr());
+                            TypeswitchExpression.Case c = new 
TypeswitchExpression.Case(caseVar, type, cExpr);
+                            cases.add(c);
                             popVariableScope();
-                            return new TypeswitchExpression(currCtx, tVar, 
cases, dExpr);
                         }
-                        */
+                        Expression dExpr = 
translateExpression(teNode.getDefaultClause());
+                        popVariableScope();
+                        return new TypeswitchExpression(currCtx, tVar, cases, 
dExpr);
+                    }
+                    */
 
             case COMPUTED_TEXT_CONSTRUCTOR: {
                 ComputedTextConstructorNode cNode = 
(ComputedTextConstructorNode) value;
@@ -1207,9 +1207,7 @@ public class XMLQueryTranslator {
             throws SystemException {
         List<ILogicalExpression> content = new ArrayList<ILogicalExpression>();
         for (ASTNode aVal : obj.getContent()) {
-            String key = ((PairConstructor) aVal).getKey();
-            ILogicalExpression ke = 
ce(SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE),
-                    unquote(key));
+            ILogicalExpression ke = 
string(data(vre(translateExpression(((PairConstructor) aVal).getKey(), tCtx))));
             content.add(ke);
             ILogicalExpression ve = vre(translateExpression(((PairConstructor) 
aVal).getValue(), tCtx));
             content.add(ve);
@@ -2082,6 +2080,10 @@ public class XMLQueryTranslator {
         return new ScalarFunctionCallExpression(BuiltinFunctions.FN_DATA_1, 
Collections.singletonList(mutable(expr)));
     }
 
+    private ILogicalExpression string(ILogicalExpression expr) throws 
SystemException {
+        return new ScalarFunctionCallExpression(BuiltinFunctions.FN_STRING_1, 
Collections.singletonList(mutable(expr)));
+    }
+
     private ILogicalExpression promote(ILogicalExpression expr, SequenceType 
type) throws SystemException {
         int typeCode = currCtx.lookupSequenceType(type);
         return sfce(BuiltinOperators.PROMOTE, expr,

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-core/src/main/javacc/xquery-grammar.jj
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/javacc/xquery-grammar.jj 
b/vxquery-core/src/main/javacc/xquery-grammar.jj
index df92e33..fe72ba7 100644
--- a/vxquery-core/src/main/javacc/xquery-grammar.jj
+++ b/vxquery-core/src/main/javacc/xquery-grammar.jj
@@ -2033,14 +2033,11 @@ ASTNode ObjectConstructor() :
 
 ASTNode PairConstructor() :
 {
-    String key;
+    ASTNode key;
     ASTNode value;
-    Token t;
 }
 {
-    t = <StringLiteral> {
-        key = t.image;
-    }
+    key = ExprSingle()
     (
         ":"
         | ":?"
@@ -2048,7 +2045,7 @@ ASTNode PairConstructor() :
     (
         value = ExprSingle()
     ) {
-        PairConstructor pc = new PairConstructor(createSourceLocation(t));
+        PairConstructor pc = new PairConstructor(key.getSourceLocation());
         pc.setKey(key);
         pc.setValue(value);
         return pc;

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q09_object.txt
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q09_object.txt
 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q09_object.txt
new file mode 100644
index 0000000..4ba7ae0
--- /dev/null
+++ 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q09_object.txt
@@ -0,0 +1 @@
+{"123":456}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q10_object.txt
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q10_object.txt
 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q10_object.txt
new file mode 100644
index 0000000..4ba583a
--- /dev/null
+++ 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q10_object.txt
@@ -0,0 +1 @@
+{"123":{"array":1}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q07_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q07_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q07_object.xq
index dee64ae..ecfcfb5 100644
--- a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q07_object.xq
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q07_object.xq
@@ -16,7 +16,7 @@
    under the License. :)
 
 (: Json Object Query :)
-(: Pasrse object with arrays :)
+(: Object having two pairs with the same name :)
 {
     "a":123,
     "a":234,

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q08_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q08_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q08_object.xq
new file mode 100644
index 0000000..6450eb2
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q08_object.xq
@@ -0,0 +1,22 @@
+(: 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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-215 :)
+{
+    [1,2,3] : "Numbers"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q09_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q09_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q09_object.xq
new file mode 100644
index 0000000..4a7d6db
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q09_object.xq
@@ -0,0 +1,22 @@
+(: 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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-215 :)
+{
+    123 : 456
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q10_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q10_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q10_object.xq
new file mode 100644
index 0000000..99cdb8f
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q10_object.xq
@@ -0,0 +1,24 @@
+(: 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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-215 :)
+{
+    <Number>123</Number> : {
+                        "array":1
+                        }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q11_object.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q11_object.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q11_object.xq
new file mode 100644
index 0000000..0b6a169
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q11_object.xq
@@ -0,0 +1,23 @@
+(: 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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-215 :)
+{
+    <Name>Joe</Name> : "Joe",
+    "Joe" : "Name"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ba6af988/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml 
b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
index 8543d3a..9bba114 100644
--- a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
@@ -55,4 +55,24 @@
         <query name="q07_object" date="2016-06-14"/>
         <expected-error>JNDY0003</expected-error>
     </test-case>
+    <test-case name="json-object-q08" FilePath="Json/Object/" Creator="Riyafa 
Abdul Hameed">
+        <description>Object.</description>
+        <query name="q08_object" date="2016-06-30"/>
+        <expected-error>JNTY0004</expected-error>
+    </test-case>
+    <test-case name="json-object-q09" FilePath="Json/Object/" Creator="Riyafa 
Abdul Hameed">
+        <description>Object.</description>
+        <query name="q09_object" date="2016-06-30"/>
+        <output-file compare="Text">q09_object.txt</output-file>
+    </test-case>
+    <test-case name="json-object-q10" FilePath="Json/Object/" Creator="Riyafa 
Abdul Hameed">
+        <description>Object.</description>
+        <query name="q10_object" date="2016-06-30"/>
+        <output-file compare="Text">q10_object.txt</output-file>
+    </test-case>
+    <test-case name="json-object-q11" FilePath="Json/Object/" Creator="Riyafa 
Abdul Hameed">
+        <description>Object.</description>
+        <query name="q11_object" date="2016-06-30"/>
+        <expected-error>JNDY0003</expected-error>
+    </test-case>
 </test-group>
\ No newline at end of file

Reply via email to