This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit 128ad89196543fcb45e82313b11fae7ec8cfa6a1 Author: Andy Seaborne <[email protected]> AuthorDate: Tue Mar 4 11:26:46 2025 +0000 Don't include JSON template in query projection; do compare JSON template --- jena-arq/Grammar/arq.jj | 8 +-- jena-arq/Grammar/main.jj | 9 ++- .../org/apache/jena/sparql/core/QueryCompare.java | 1 + .../org/apache/jena/sparql/lang/arq/ARQParser.java | 8 +-- .../jena/sparql/lang/sparql_12/JavaCharStream.java | 79 +++++++++++----------- 5 files changed, 53 insertions(+), 52 deletions(-) diff --git a/jena-arq/Grammar/arq.jj b/jena-arq/Grammar/arq.jj index 4ffca766a3..9bba04ac77 100644 --- a/jena-arq/Grammar/arq.jj +++ b/jena-arq/Grammar/arq.jj @@ -201,10 +201,10 @@ void JsonObjectMember() : { Node o ; String s ; Token t; } throwParseException("Prefix name expression not legal at this point : "+t.image, t.beginLine, t.beginColumn) ; } ( - o = Var() { getQuery().addResultVar((Var)o) ; getQuery().addJsonMapping(s, o) ; } - | o = RDFLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } - | o = NumericLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } - | o = BooleanLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } + o = Var() { getQuery().addJsonMapping(s, o) ; } + | o = RDFLiteral() { getQuery().addJsonMapping(s, o) ; } + | o = NumericLiteral() { getQuery().addJsonMapping(s, o) ; } + | o = BooleanLiteral() { getQuery().addJsonMapping(s, o) ; } ) } void DatasetClause() : {} diff --git a/jena-arq/Grammar/main.jj b/jena-arq/Grammar/main.jj index 9f14ca6330..c2e017982b 100644 --- a/jena-arq/Grammar/main.jj +++ b/jena-arq/Grammar/main.jj @@ -361,13 +361,12 @@ void JsonObjectMember() : { Node o ; String s ; Token t; } throwParseException("Prefix name expression not legal at this point : "+t.image, t.beginLine, t.beginColumn) ; } ( - o = Var() { getQuery().addResultVar((Var)o) ; getQuery().addJsonMapping(s, o) ; } - | o = RDFLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } - | o = NumericLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } - | o = BooleanLiteral() { getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; } + o = Var() { getQuery().addJsonMapping(s, o) ; } + | o = RDFLiteral() { getQuery().addJsonMapping(s, o) ; } + | o = NumericLiteral() { getQuery().addJsonMapping(s, o) ; } + | o = BooleanLiteral() { getQuery().addJsonMapping(s, o) ; } ) } - #endif // ---- diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/QueryCompare.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/QueryCompare.java index cb3c14c672..eba7f1e841 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/core/QueryCompare.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/QueryCompare.java @@ -96,6 +96,7 @@ public class QueryCompare implements QueryVisitor @Override public void visitJsonResultForm(Query query) { check("Not both JSON queries", query2.isJsonType()); + check("Json mapping", query.getJsonMapping(), query2.getJsonMapping()); } @Override diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/lang/arq/ARQParser.java b/jena-arq/src/main/java/org/apache/jena/sparql/lang/arq/ARQParser.java index dec80e38c2..59630e573b 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/lang/arq/ARQParser.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/lang/arq/ARQParser.java @@ -778,7 +778,7 @@ if ( ! t.image.equals(":") ) case VAR1: case VAR2:{ o = Var(); -getQuery().addResultVar((Var)o) ; getQuery().addJsonMapping(s, o) ; +getQuery().addJsonMapping(s, o) ; break; } case STRING_LITERAL1: @@ -786,7 +786,7 @@ getQuery().addResultVar((Var)o) ; getQuery().addJsonMapping(s, o) ; case STRING_LITERAL_LONG1: case STRING_LITERAL_LONG2:{ o = RDFLiteral(); -getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; +getQuery().addJsonMapping(s, o) ; break; } case INTEGER: @@ -799,13 +799,13 @@ getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, case DECIMAL_NEGATIVE: case DOUBLE_NEGATIVE:{ o = NumericLiteral(); -getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; +getQuery().addJsonMapping(s, o) ; break; } case TRUE: case FALSE:{ o = BooleanLiteral(); -getQuery().addResultVar(s, NodeValue.makeNode(o)) ; getQuery().addJsonMapping(s, o) ; +getQuery().addJsonMapping(s, o) ; break; } default: diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/lang/sparql_12/JavaCharStream.java b/jena-arq/src/main/java/org/apache/jena/sparql/lang/sparql_12/JavaCharStream.java index cc5a770079..e47a4e5883 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/lang/sparql_12/JavaCharStream.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/lang/sparql_12/JavaCharStream.java @@ -13,7 +13,7 @@ public class JavaCharStream { /** Whether parser is static. */ - + @SuppressWarnings("all") public static final boolean staticFlag = false; @@ -65,7 +65,7 @@ public static final boolean staticFlag = false; } /* Position in buffer. */ - + @SuppressWarnings("all") public int bufpos = -1; int bufsize; @@ -90,10 +90,10 @@ public int bufpos = -1; protected int tabSize = 1; protected boolean trackLineColumn = true; - + @SuppressWarnings("all") public void setTabSize(int i) { tabSize = i; } - + @SuppressWarnings("all") public int getTabSize() { return tabSize; } @@ -185,7 +185,7 @@ public int getTabSize() { return tabSize; } } /* @return starting character for token. */ - + @SuppressWarnings("all") public char BeginToken() throws java.io.IOException { @@ -267,7 +267,7 @@ public char BeginToken() throws java.io.IOException } /* Read a character. */ - + @SuppressWarnings("all") public char readChar() throws java.io.IOException { @@ -367,7 +367,7 @@ public char readChar() throws java.io.IOException * @see #getEndColumn */ @Deprecated - + @SuppressWarnings("all") public int getColumn() { return bufcolumn[bufpos]; @@ -379,7 +379,7 @@ public int getColumn() { * @return the line number. */ @Deprecated - + @SuppressWarnings("all") public int getLine() { return bufline[bufpos]; @@ -388,7 +388,7 @@ public int getLine() { /** Get end column. * @return the end column or -1 */ - + @SuppressWarnings("all") public int getEndColumn() { return bufcolumn[bufpos]; @@ -397,7 +397,7 @@ public int getEndColumn() { /** Get end line. * @return the end line number or -1 */ - + @SuppressWarnings("all") public int getEndLine() { return bufline[bufpos]; @@ -405,21 +405,21 @@ public int getEndLine() { /** Get the beginning column. * @return column of token start */ - + @SuppressWarnings("all") public int getBeginColumn() { return bufcolumn[tokenBegin]; } /** @return line number of token start */ - + @SuppressWarnings("all") public int getBeginLine() { return bufline[tokenBegin]; } /** Retreat. */ - + @SuppressWarnings("all") public void backup(int amount) { @@ -434,7 +434,7 @@ public void backup(int amount) { * @param startcolumn column number of the first character of the stream. * @param buffersize size of the buffer */ - + @SuppressWarnings("all") public JavaCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) @@ -455,7 +455,7 @@ public JavaCharStream(java.io.Reader dstream, * @param startline line number of the first character of the stream, mostly for error messages. * @param startcolumn column number of the first character of the stream. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.Reader dstream, int startline, int startcolumn) @@ -465,15 +465,16 @@ public JavaCharStream(java.io.Reader dstream, /** Constructor. * @param dstream the underlying data source. + * @param startline line number of the first character of the stream, mostly for error messages. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.Reader dstream) { this(dstream, 1, 1, 4096); } /* Reinitialise. */ - + @SuppressWarnings("all") public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) @@ -496,7 +497,7 @@ public void ReInit(java.io.Reader dstream, } /* Reinitialise. */ - + @SuppressWarnings("all") public void ReInit(java.io.Reader dstream, int startline, int startcolumn) @@ -505,14 +506,14 @@ public void ReInit(java.io.Reader dstream, } /* Reinitialise. */ - + @SuppressWarnings("all") public void ReInit(java.io.Reader dstream) { ReInit(dstream, 1, 1, 4096); } /** Constructor. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException @@ -526,7 +527,7 @@ public JavaCharStream(java.io.InputStream dstream, String encoding, int startlin * @param startcolumn column number of the first character of the stream. * @param buffersize size of the buffer */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) @@ -539,9 +540,9 @@ public JavaCharStream(java.io.InputStream dstream, int startline, * @param encoding the character encoding of the data stream. * @param startline line number of the first character of the stream, mostly for error messages. * @param startcolumn column number of the first character of the stream. - * @throws java.io.UnsupportedEncodingException encoding is invalid or unsupported. + * @throws UnsupportedEncodingException encoding is invalid or unsupported. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException @@ -554,7 +555,7 @@ public JavaCharStream(java.io.InputStream dstream, String encoding, int startlin * @param startline line number of the first character of the stream, mostly for error messages. * @param startcolumn column number of the first character of the stream. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream, int startline, int startcolumn) @@ -565,9 +566,9 @@ public JavaCharStream(java.io.InputStream dstream, int startline, /** Constructor. * @param dstream the underlying data source. * @param encoding the character encoding of the data stream. - * @throws java.io.UnsupportedEncodingException encoding is invalid or unsupported. + * @throws UnsupportedEncodingException encoding is invalid or unsupported. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { @@ -577,7 +578,7 @@ public JavaCharStream(java.io.InputStream dstream, String encoding) throws java. /** Constructor. * @param dstream the underlying data source. */ - + @SuppressWarnings("all") public JavaCharStream(java.io.InputStream dstream) { @@ -591,7 +592,7 @@ public JavaCharStream(java.io.InputStream dstream) * @param startcolumn column number of the first character of the stream. * @param buffersize size of the buffer */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException @@ -605,7 +606,7 @@ public void ReInit(java.io.InputStream dstream, String encoding, int startline, * @param startcolumn column number of the first character of the stream. * @param buffersize size of the buffer */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) @@ -617,9 +618,9 @@ public void ReInit(java.io.InputStream dstream, int startline, * @param encoding the character encoding of the data stream. * @param startline line number of the first character of the stream, mostly for error messages. * @param startcolumn column number of the first character of the stream. - * @throws java.io.UnsupportedEncodingException encoding is invalid or unsupported. + * @throws UnsupportedEncodingException encoding is invalid or unsupported. */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException @@ -631,7 +632,7 @@ public void ReInit(java.io.InputStream dstream, String encoding, int startline, * @param startline line number of the first character of the stream, mostly for error messages. * @param startcolumn column number of the first character of the stream. */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) @@ -641,9 +642,9 @@ public void ReInit(java.io.InputStream dstream, int startline, /** Reinitialise. * @param dstream the underlying data source. * @param encoding the character encoding of the data stream. - * @throws java.io.UnsupportedEncodingException encoding is invalid or unsupported. + * @throws UnsupportedEncodingException encoding is invalid or unsupported. */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { @@ -653,7 +654,7 @@ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io. /** Reinitialise. * @param dstream the underlying data source. */ - + @SuppressWarnings("all") public void ReInit(java.io.InputStream dstream) { @@ -662,7 +663,7 @@ public void ReInit(java.io.InputStream dstream) /** Get the token timage. * @return token image as String */ - + @SuppressWarnings("all") public String GetImage() { @@ -676,7 +677,7 @@ public String GetImage() /** Get the suffix as an array of characters. * @param len the length of the array to return. * @return suffix */ - + @SuppressWarnings("all") public char[] GetSuffix(int len) { @@ -695,7 +696,7 @@ public char[] GetSuffix(int len) } /** Set buffers back to null when finished. */ - + @SuppressWarnings("all") public void Done() { @@ -711,7 +712,7 @@ public void Done() * @param newLine the new line number. * @param newCol the new column number. */ - + @SuppressWarnings("all") public void adjustBeginLineColumn(int newLine, int newCol) {
