[jira] [Assigned] (RYA-22) MongoDBRyaDAO silently throws exceptions
[ https://issues.apache.org/jira/browse/RYA-22?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] David W. Lotts reassigned RYA-22: - Assignee: (was: David W. Lotts) > MongoDBRyaDAO silently throws exceptions > > > Key: RYA-22 > URL: https://issues.apache.org/jira/browse/RYA-22 > Project: Rya > Issue Type: Bug > Components: dao >Affects Versions: 3.2.9 >Reporter: Aaron Mihalik >Priority: Trivial > Labels: beginner > > {{MongoDBRyaDAO}} throws a handful of exceptions during init. These > exceptions should probably be re-thrown as {{RyaDAOException}} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374856#comment-16374856 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170322179 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); --- End diff -- I don't think this will work in all cases. It looks like the following query would incorrectly be considered a CONSTRUCT query: ``` SELECT ?constructionCompany WHERE { ?constructionCompany . } ``` Instead, try checking if the result of `PARSER.parseQuery()` is a `ParsedGraphQuery`: ``` final ParsedQuery parsedQuery = PARSER.parseQuery(sparql, null); return parsedQuery instanceof ParsedGraphQuery; ``` > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374855#comment-16374855 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170336478 --- Diff: extras/rya.streams/client/src/main/java/org/apache/rya/streams/client/command/StreamResultsCommand.java --- @@ -167,17 +182,38 @@ public void run() { throw new ExecutionException("Could not parse the SPARQL for the query: " + sparql, e); } -// Iterate through the results and print them to the console until the program or the stream ends. -try (final QueryResultStream stream = getQueryResultStream.fromStart(queryId)) { -while(!finished.get()) { -for(final Object result : stream.poll(1000)) { -System.out.println(result); +// Iterate through the results and print them to the configured output mechanism. +try (final QueryResultStream resultsStream = getQueryResultStream.fromStart(queryId)) { +final TupleExpr tupleExpr = new SPARQLParser().parseQuery(sparql, null).getTupleExpr(); +if(params.outputPath != null) { +final Path file = Paths.get(params.outputPath); +try(OutputStream out = Files.newOutputStream(file)) { --- End diff -- try(final OutputStream out ... > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374852#comment-16374852 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329299 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); + +} catch(final MalformedQueryException queryE) { +try { +// Maybe it's an update. +PARSER.parseUpdate(sparql, null); + +// It was, so return false. +return false; + +} catch(final MalformedQueryException updateE) { +// It's not. Actually malformed. +throw queryE; +} +} +} + +/** + * Determines whether a SPARQL command is an INSERT with a WHERE clause or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is an INSERT update; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isInsertWhere(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Inserts are updated, so try to create a ParsedUpdate. +PARSER.parseUpdate(sparql, null); + +// Check to see if the SPARQL looks like an INSERT query. +return Pattern.matches(".*?insert.*?where.*", sparql.toLowerCase()); --- End diff -- Again, this could lead to false positives. Such as: ``` DELETE { ?bookInsert ?p ?o } WHERE { ?bookInsert ?datePrinted . FILTER ( ?datePrinted < "2018-01-01T00:00:00"^^xsd:dateTime ) ?bookInsert ?p ?o } ``` It should be either an INSERT or DELETE by the time it reaches the pattern matcher. However, INSERT and DELETE are both considered `ParsedUpdate`s without any extra subclasses to distinguish them so it needs to be handled differently from the CONSTRUCT query parsing above. Maybe try: ``` PARSER.parseUpdate(sparql, null); final String strippedOperation =
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374853#comment-16374853 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170336740 --- Diff: extras/rya.streams/client/src/main/java/org/apache/rya/streams/client/command/StreamResultsCommand.java --- @@ -167,17 +182,38 @@ public void run() { throw new ExecutionException("Could not parse the SPARQL for the query: " + sparql, e); } -// Iterate through the results and print them to the console until the program or the stream ends. -try (final QueryResultStream stream = getQueryResultStream.fromStart(queryId)) { -while(!finished.get()) { -for(final Object result : stream.poll(1000)) { -System.out.println(result); +// Iterate through the results and print them to the configured output mechanism. +try (final QueryResultStream resultsStream = getQueryResultStream.fromStart(queryId)) { +final TupleExpr tupleExpr = new SPARQLParser().parseQuery(sparql, null).getTupleExpr(); +if(params.outputPath != null) { +final Path file = Paths.get(params.outputPath); +try(OutputStream out = Files.newOutputStream(file)) { +if(isStatementResults) { +final QueryResultStream stmtStream = (QueryResultStream) resultsStream; +QueryResultsOutputUtil.toNtriplesFile(out, stmtStream, finished); +} else { +final QueryResultStream bsStream = (QueryResultStream) resultsStream; +QueryResultsOutputUtil.toBindingSetJSONFile(out, tupleExpr, bsStream, finished); +} } +} else { +streamToSystemOut(resultsStream, finished); } } catch (final Exception e) { System.err.println("Error while reading the results from the stream."); e.printStackTrace(); System.exit(1); } } + +private void streamToSystemOut(final QueryResultStream stream, final AtomicBoolean shutdownSignal) throws Exception { --- End diff -- make static > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374854#comment-16374854 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329580 --- Diff: common/rya.api/src/test/java/org/apache/rya/api/utils/QueryInvestigatorTest.java --- @@ -0,0 +1,123 @@ +/** + * 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.rya.api.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; + +/** + * Unit tests the methods of {@link }. --- End diff -- fill in `{@link}` > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374857#comment-16374857 ] ASF GitHub Bot commented on RYA-466: Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329694 --- Diff: common/rya.api/src/test/java/org/apache/rya/api/utils/QueryInvestigatorTest.java --- @@ -0,0 +1,123 @@ +/** + * 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.rya.api.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; + +/** + * Unit tests the methods of {@link }. + */ +public class QueryInvestigatorTest { --- End diff -- Add tests for potential false positives mentioned above. > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170336478 --- Diff: extras/rya.streams/client/src/main/java/org/apache/rya/streams/client/command/StreamResultsCommand.java --- @@ -167,17 +182,38 @@ public void run() { throw new ExecutionException("Could not parse the SPARQL for the query: " + sparql, e); } -// Iterate through the results and print them to the console until the program or the stream ends. -try (final QueryResultStream stream = getQueryResultStream.fromStart(queryId)) { -while(!finished.get()) { -for(final Object result : stream.poll(1000)) { -System.out.println(result); +// Iterate through the results and print them to the configured output mechanism. +try (final QueryResultStream resultsStream = getQueryResultStream.fromStart(queryId)) { +final TupleExpr tupleExpr = new SPARQLParser().parseQuery(sparql, null).getTupleExpr(); +if(params.outputPath != null) { +final Path file = Paths.get(params.outputPath); +try(OutputStream out = Files.newOutputStream(file)) { --- End diff -- try(final OutputStream out ... ---
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329580 --- Diff: common/rya.api/src/test/java/org/apache/rya/api/utils/QueryInvestigatorTest.java --- @@ -0,0 +1,123 @@ +/** + * 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.rya.api.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; + +/** + * Unit tests the methods of {@link }. --- End diff -- fill in `{@link}` ---
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329694 --- Diff: common/rya.api/src/test/java/org/apache/rya/api/utils/QueryInvestigatorTest.java --- @@ -0,0 +1,123 @@ +/** + * 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.rya.api.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; + +/** + * Unit tests the methods of {@link }. + */ +public class QueryInvestigatorTest { --- End diff -- Add tests for potential false positives mentioned above. ---
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170336740 --- Diff: extras/rya.streams/client/src/main/java/org/apache/rya/streams/client/command/StreamResultsCommand.java --- @@ -167,17 +182,38 @@ public void run() { throw new ExecutionException("Could not parse the SPARQL for the query: " + sparql, e); } -// Iterate through the results and print them to the console until the program or the stream ends. -try (final QueryResultStream stream = getQueryResultStream.fromStart(queryId)) { -while(!finished.get()) { -for(final Object result : stream.poll(1000)) { -System.out.println(result); +// Iterate through the results and print them to the configured output mechanism. +try (final QueryResultStream resultsStream = getQueryResultStream.fromStart(queryId)) { +final TupleExpr tupleExpr = new SPARQLParser().parseQuery(sparql, null).getTupleExpr(); +if(params.outputPath != null) { +final Path file = Paths.get(params.outputPath); +try(OutputStream out = Files.newOutputStream(file)) { +if(isStatementResults) { +final QueryResultStream stmtStream = (QueryResultStream) resultsStream; +QueryResultsOutputUtil.toNtriplesFile(out, stmtStream, finished); +} else { +final QueryResultStream bsStream = (QueryResultStream) resultsStream; +QueryResultsOutputUtil.toBindingSetJSONFile(out, tupleExpr, bsStream, finished); +} } +} else { +streamToSystemOut(resultsStream, finished); } } catch (final Exception e) { System.err.println("Error while reading the results from the stream."); e.printStackTrace(); System.exit(1); } } + +private void streamToSystemOut(final QueryResultStream stream, final AtomicBoolean shutdownSignal) throws Exception { --- End diff -- make static ---
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170322179 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); --- End diff -- I don't think this will work in all cases. It looks like the following query would incorrectly be considered a CONSTRUCT query: ``` SELECT ?constructionCompany WHERE { ?constructionCompany . } ``` Instead, try checking if the result of `PARSER.parseQuery()` is a `ParsedGraphQuery`: ``` final ParsedQuery parsedQuery = PARSER.parseQuery(sparql, null); return parsedQuery instanceof ParsedGraphQuery; ``` ---
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user ejwhite922 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170329299 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); + +} catch(final MalformedQueryException queryE) { +try { +// Maybe it's an update. +PARSER.parseUpdate(sparql, null); + +// It was, so return false. +return false; + +} catch(final MalformedQueryException updateE) { +// It's not. Actually malformed. +throw queryE; +} +} +} + +/** + * Determines whether a SPARQL command is an INSERT with a WHERE clause or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is an INSERT update; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isInsertWhere(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Inserts are updated, so try to create a ParsedUpdate. +PARSER.parseUpdate(sparql, null); + +// Check to see if the SPARQL looks like an INSERT query. +return Pattern.matches(".*?insert.*?where.*", sparql.toLowerCase()); --- End diff -- Again, this could lead to false positives. Such as: ``` DELETE { ?bookInsert ?p ?o } WHERE { ?bookInsert ?datePrinted . FILTER ( ?datePrinted < "2018-01-01T00:00:00"^^xsd:dateTime ) ?bookInsert ?p ?o } ``` It should be either an INSERT or DELETE by the time it reaches the pattern matcher. However, INSERT and DELETE are both considered `ParsedUpdate`s without any extra subclasses to distinguish them so it needs to be handled differently from the CONSTRUCT query parsing above. Maybe try: ``` PARSER.parseUpdate(sparql, null); final String strippedOperation = QueryParserUtil.removeSPARQLQueryProlog(sparql.toLowerCase()); return strippedOperation.startsWith("insert"); ``` ---
[jira] [Commented] (RYA-466) Rya Streams Client - Stream results to file.
[ https://issues.apache.org/jira/browse/RYA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374709#comment-16374709 ] ASF GitHub Bot commented on RYA-466: Github user isper3at commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170314969 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); + +} catch(final MalformedQueryException queryE) { +try { +// Maybe it's an update. +PARSER.parseUpdate(sparql, null); + +// It was, so return false. +return false; + +} catch(final MalformedQueryException updateE) { +// It's not. Actually malformed. +throw queryE; +} +} +} + +/** + * Determines whether a SPARQL command is an INSERT with a WHERE clause or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is an INSERT update; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isInsertWhere(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Inserts are updated, so try to create a ParsedUpdate. +PARSER.parseUpdate(sparql, null); + +// Check to see if the SPARQL looks like an INSERT query. +return Pattern.matches(".*?insert.*?where.*", sparql.toLowerCase()); --- End diff -- odd thought, what if the query is something like INSERT { a ?where b } > Rya Streams Client - Stream results to file. > > > Key: RYA-466 > URL: https://issues.apache.org/jira/browse/RYA-466 > Project: Rya > Issue Type: Improvement >Reporter: Kevin Chilton >Assignee: Kevin Chilton >Priority: Major > > The Rya Streams Client's stream results command needs to be updated to allow > a user to stream Statement results to an NTriples file and Binding Sets to > the standard JSON representation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[GitHub] incubator-rya pull request #275: RYA-466 Update the Rya Streams Client to st...
Github user isper3at commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/275#discussion_r170314969 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/utils/QueryInvestigator.java --- @@ -0,0 +1,104 @@ +/** + * 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.rya.api.utils; + +import static java.util.Objects.requireNonNull; + +import java.util.regex.Pattern; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that is used to glean insight into the structure of SPARQL queries. + */ +@DefaultAnnotation(NonNull.class) +public class QueryInvestigator { + +private static final SPARQLParser PARSER = new SPARQLParser(); + +private QueryInvestigator() { } + +/** + * Determines whether a SPARQL command is a CONSTRUCT or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is a CONSTRUCT query; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isConstruct(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Constructs are queries, so try to create a ParsedQuery. +PARSER.parseQuery(sparql, null); + +// Check to see if the SPARQL looks like a CONSTRUCT query. +return Pattern.matches(".*?construct.*?where.*", sparql.toLowerCase()); + +} catch(final MalformedQueryException queryE) { +try { +// Maybe it's an update. +PARSER.parseUpdate(sparql, null); + +// It was, so return false. +return false; + +} catch(final MalformedQueryException updateE) { +// It's not. Actually malformed. +throw queryE; +} +} +} + +/** + * Determines whether a SPARQL command is an INSERT with a WHERE clause or not. + * + * @param sparql - The SPARQL to evaluate. (not null) + * @return {@code true} if the provided SPARQL is an INSERT update; otherwise {@code false}. + * @throws MalformedQueryException The SPARQL is neither a well formed query or update. + */ +public static boolean isInsertWhere(final String sparql) throws MalformedQueryException { +requireNonNull(sparql); + +try { +// Inserts are updated, so try to create a ParsedUpdate. +PARSER.parseUpdate(sparql, null); + +// Check to see if the SPARQL looks like an INSERT query. +return Pattern.matches(".*?insert.*?where.*", sparql.toLowerCase()); --- End diff -- odd thought, what if the query is something like INSERT { a ?where b } ---
[jira] [Commented] (RYA-405) Migrate from Sesame to rdf4j libs
[ https://issues.apache.org/jira/browse/RYA-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374534#comment-16374534 ] ASF GitHub Bot commented on RYA-405: Github user asfgit commented on the issue: https://github.com/apache/incubator-rya/pull/245 Refer to this link for build results (access rights to CI server needed): https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/697/ > Migrate from Sesame to rdf4j libs > -- > > Key: RYA-405 > URL: https://issues.apache.org/jira/browse/RYA-405 > Project: Rya > Issue Type: Improvement >Affects Versions: 3.2.12 >Reporter: Jorge Machado >Priority: Major > > I have migrated all the project to the newer libs from rdf4j instead of using > the old ones. > Can someone take a look ? -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[GitHub] incubator-rya issue #245: [RYA-405] Migrate from Sesame to rdf4j libs
Github user asfgit commented on the issue: https://github.com/apache/incubator-rya/pull/245 Refer to this link for build results (access rights to CI server needed): https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/697/ ---
[jira] [Updated] (RYA-471) Ensure that Rya can be built with Java 9
[ https://issues.apache.org/jira/browse/RYA-471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jeff Dasch updated RYA-471: --- Description: There have been some issues reported building Rya on Windows on Java 9. I did a quick check trying to build Rya 3.2.12-RC1 on MacOS. I didn't have the same failures as reported on Windows, but I did have some problems with some tests. * Ensure that Rya can be built on Windows, Mac and Linux with the latest JDK9. * See if there are any runtime issues with running * Keep the maven-compiler-plugin's source and target versions set to 1.8 so we still work with both versions of the JDK. was: There have been some issues reported building Rya on Windows on Java 9. I did a quick check trying to build Rya 3.2.12 on MacOS. I didn't have the same failures as reported on Windows, but I did have some problems with some tests. * Ensure that Rya can be built on Windows, Mac and Linux with the latest JDK9. * See if there are any runtime issues with running * Keep the maven-compiler-plugin's source and target versions set to 1.8 so we still work with both versions of the JDK. > Ensure that Rya can be built with Java 9 > > > Key: RYA-471 > URL: https://issues.apache.org/jira/browse/RYA-471 > Project: Rya > Issue Type: Improvement > Components: build >Affects Versions: 3.2.12 >Reporter: Jeff Dasch >Priority: Minor > > There have been some issues reported building Rya on Windows on Java 9. I > did a quick check trying to build Rya 3.2.12-RC1 on MacOS. I didn't have the > same failures as reported on Windows, but I did have some problems with some > tests. > * Ensure that Rya can be built on Windows, Mac and Linux with the latest > JDK9. > * See if there are any runtime issues with running > * Keep the maven-compiler-plugin's source and target versions set to 1.8 so > we still work with both versions of the JDK. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Comment Edited] (RYA-471) Ensure that Rya can be built with Java 9
[ https://issues.apache.org/jira/browse/RYA-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374478#comment-16374478 ] Jeff Dasch edited comment on RYA-471 at 2/23/18 3:17 PM: - As reported by Dave Jones on the dev list: http://mail-archives.apache.org/mod_mbox/incubator-rya-dev/201802.mbox/%3C2EDF95F9054CF5499721741792413AD70266576D29%40SRV-EXCH-02.kbsi-cs.com%3E was (Author: jdasch): As reported by Dave Jones on the dev list: http://mail-archives.apache.org/mod_mbox/incubator-rya-dev/201802.mbox/browser > Ensure that Rya can be built with Java 9 > > > Key: RYA-471 > URL: https://issues.apache.org/jira/browse/RYA-471 > Project: Rya > Issue Type: Improvement > Components: build >Affects Versions: 3.2.12 >Reporter: Jeff Dasch >Priority: Minor > > There have been some issues reported building Rya on Windows on Java 9. I > did a quick check trying to build Rya 3.2.12 on MacOS. I didn't have the > same failures as reported on Windows, but I did have some problems with some > tests. > * Ensure that Rya can be built on Windows, Mac and Linux with the latest > JDK9. > * See if there are any runtime issues with running > * Keep the maven-compiler-plugin's source and target versions set to 1.8 so > we still work with both versions of the JDK. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-471) Ensure that Rya can be built with Java 9
[ https://issues.apache.org/jira/browse/RYA-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374478#comment-16374478 ] Jeff Dasch commented on RYA-471: As reported by Dave Jones on the dev list: http://mail-archives.apache.org/mod_mbox/incubator-rya-dev/201802.mbox/browser > Ensure that Rya can be built with Java 9 > > > Key: RYA-471 > URL: https://issues.apache.org/jira/browse/RYA-471 > Project: Rya > Issue Type: Improvement > Components: build >Affects Versions: 3.2.12 >Reporter: Jeff Dasch >Priority: Minor > > There have been some issues reported building Rya on Windows on Java 9. I > did a quick check trying to build Rya 3.2.12 on MacOS. I didn't have the > same failures as reported on Windows, but I did have some problems with some > tests. > * Ensure that Rya can be built on Windows, Mac and Linux with the latest > JDK9. > * See if there are any runtime issues with running > * Keep the maven-compiler-plugin's source and target versions set to 1.8 so > we still work with both versions of the JDK. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Updated] (RYA-471) Ensure that Rya can be built with Java 9
[ https://issues.apache.org/jira/browse/RYA-471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jeff Dasch updated RYA-471: --- Summary: Ensure that Rya can be built with Java 9 (was: Ensure that Rya can be built on Java 9.) > Ensure that Rya can be built with Java 9 > > > Key: RYA-471 > URL: https://issues.apache.org/jira/browse/RYA-471 > Project: Rya > Issue Type: Improvement > Components: build >Affects Versions: 3.2.12 >Reporter: Jeff Dasch >Priority: Minor > > There have been some issues reported building Rya on Windows on Java 9. I > did a quick check trying to build Rya 3.2.12 on MacOS. I didn't have the > same failures as reported on Windows, but I did have some problems with some > tests. > * Ensure that Rya can be built on Windows, Mac and Linux with the latest > JDK9. > * See if there are any runtime issues with running > * Keep the maven-compiler-plugin's source and target versions set to 1.8 so > we still work with both versions of the JDK. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Created] (RYA-471) Ensure that Rya can be built on Java 9.
Jeff Dasch created RYA-471: -- Summary: Ensure that Rya can be built on Java 9. Key: RYA-471 URL: https://issues.apache.org/jira/browse/RYA-471 Project: Rya Issue Type: Improvement Components: build Affects Versions: 3.2.12 Reporter: Jeff Dasch There have been some issues reported building Rya on Windows on Java 9. I did a quick check trying to build Rya 3.2.12 on MacOS. I didn't have the same failures as reported on Windows, but I did have some problems with some tests. * Ensure that Rya can be built on Windows, Mac and Linux with the latest JDK9. * See if there are any runtime issues with running * Keep the maven-compiler-plugin's source and target versions set to 1.8 so we still work with both versions of the JDK. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (RYA-405) Migrate from Sesame to rdf4j libs
[ https://issues.apache.org/jira/browse/RYA-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16374461#comment-16374461 ] ASF GitHub Bot commented on RYA-405: Github user theRealImy commented on the issue: https://github.com/apache/incubator-rya/pull/245 Hi there, this is interesting work and in my company we are looking forward to test out Apache Rya. However we use rdf4j already. Any idea when a new release in sight? I saw it was not added in the last RC. > Migrate from Sesame to rdf4j libs > -- > > Key: RYA-405 > URL: https://issues.apache.org/jira/browse/RYA-405 > Project: Rya > Issue Type: Improvement >Affects Versions: 3.2.12 >Reporter: Jorge Machado >Priority: Major > > I have migrated all the project to the newer libs from rdf4j instead of using > the old ones. > Can someone take a look ? -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[GitHub] incubator-rya issue #245: [RYA-405] Migrate from Sesame to rdf4j libs
Github user theRealImy commented on the issue: https://github.com/apache/incubator-rya/pull/245 Hi there, this is interesting work and in my company we are looking forward to test out Apache Rya. However we use rdf4j already. Any idea when a new release in sight? I saw it was not added in the last RC. ---
[jira] [Created] (RYA-470) Some tests fail when built on Windows
Jeff Dasch created RYA-470: -- Summary: Some tests fail when built on Windows Key: RYA-470 URL: https://issues.apache.org/jira/browse/RYA-470 Project: Rya Issue Type: Bug Components: build Affects Versions: 3.2.12 Reporter: Jeff Dasch Eric White identified these tests as failing when built on Windows. Fix the tests and get a Windows CI build configured on [https://builds.apache.org/view/Incubator%20Projects/] to prevent regression. {noformat} extras/rya.streams/integration/src/test/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorIT.java extras/rya.streams/integration/src/test/java/org/apache/rya/streams/kafka/processors/join/JoinProcessorIT.java extras/rya.streams/integration/src/test/java/org/apache/rya/streams/kafka/processors/projection/MultiProjectionProcessorIT.java extras/rya.streams/integration/src/test/java/org/apache/rya/streams/kafka/processors/sp/StatementPatternProcessorIT.java extras/shell/src/test/java/org/apache/rya/shell/AccumuloRyaConnectionCommandsIT.java extras/shell/src/test/java/org/apache/rya/shell/MongoRyaShellIT.java{noformat} -- This message was sent by Atlassian JIRA (v7.6.3#76005)