apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.12k stars 653 forks source link

Recording substituted values #2799

Open afs opened 1 month ago

afs commented 1 month ago

Version

5.2.0

What happened?

From: https://lists.apache.org/thread/ox1hglkz3jcqp1onp2rqdk349fg2poqw

Substitution applied by QueryTransformOps does not put assignments into the projection if the query is SELECT *.

Relevant output and stacktrace

public class mainSelectStarSubstitution {
        public static void main() {
            Model model = ModelFactory.createDefaultModel();
            Binding initBinding = Binding.builder().add(Var.alloc("this"), OWL.Thing.asNode()).build();
            model.add(OWL.Thing, RDF.type, OWL.Class);
            model.add(OWL.Nothing, RDF.type, RDFS.Class);
            Query query = QueryFactory.create("SELECT * { ?this a ?type }");

            // **** Workaround.
            //query.setQueryResultStar(false);

            QueryExecution qExec = QueryExecutionDatasetBuilder.create().
                    query(query).
                    model(model).
                    // Old way
                    //initialBinding(initBinding).
                    substitution("this", OWL.Thing).
                    build();
            System.out.println("qExec.getQuery() - original query");
            System.out.println(qExec.getQuery());
            System.out.println("qExec.getQueryString() - modified query");
            System.out.println(qExec.getQueryString());
        }
    }

Are you interested in making a pull request?

Yes