Search in sources :

Example 16 with ListBindingSet

use of org.eclipse.rdf4j.query.impl.ListBindingSet in project rdf4j by eclipse.

the class QueryResultsTest method testNonBNodeBindingSet.

@Test
public void testNonBNodeBindingSet() throws QueryEvaluationException {
    tqr1.append(new ListBindingSet(twoBindingNames, foo, lit1));
    tqr2.append(new ListBindingSet(twoBindingNames, foo, lit2));
    assertFalse(QueryResults.equals(tqr1, tqr2));
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) Test(org.junit.Test)

Example 17 with ListBindingSet

use of org.eclipse.rdf4j.query.impl.ListBindingSet in project rdf4j by eclipse.

the class QueryResultsTest method testBNodeBindingSet2.

@Test
public void testBNodeBindingSet2() throws QueryEvaluationException {
    tqr1.append(new ListBindingSet(twoBindingNames, foo, bnode1));
    tqr2.append(new ListBindingSet(twoBindingNames, foo, lit1));
    assertFalse(QueryResults.equals(tqr1, tqr2));
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) Test(org.junit.Test)

Example 18 with ListBindingSet

use of org.eclipse.rdf4j.query.impl.ListBindingSet in project rdf4j by eclipse.

the class QueryResultsTest method testNonBNodeBindingSet3.

@Test
public void testNonBNodeBindingSet3() throws QueryEvaluationException {
    tqr3.append(new ListBindingSet(threeBindingNames, foo, lit1, bar));
    tqr2.append(new ListBindingSet(twoBindingNames, foo, lit1));
    assertFalse(QueryResults.equals(tqr3, tqr2));
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) Test(org.junit.Test)

Example 19 with ListBindingSet

use of org.eclipse.rdf4j.query.impl.ListBindingSet in project rdf4j by eclipse.

the class SPARQLTSVCustomTest method testSES2126QuotedLiteralIntegerAsStringImplicitType.

/**
 * Only Literals with the XML Schema numeric types should be simplified.
 *
 * @throws Exception
 */
@Test
public void testSES2126QuotedLiteralIntegerAsStringImplicitType() throws Exception {
    List<String> bindingNames = Arrays.asList("test");
    TupleQueryResult tqr = new IteratingTupleQueryResult(bindingNames, Arrays.asList(new ListBindingSet(bindingNames, SimpleValueFactory.getInstance().createLiteral("1"))));
    String result = writeTupleResult(tqr);
    assertEquals("?test\n\"1\"\n", result);
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) IteratingTupleQueryResult(org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult) IteratingTupleQueryResult(org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Test(org.junit.Test)

Example 20 with ListBindingSet

use of org.eclipse.rdf4j.query.impl.ListBindingSet in project rdf4j by eclipse.

the class BinaryQueryResultParser method parse.

@Override
public synchronized void parse(InputStream in) throws IOException, QueryResultParseException, TupleQueryResultHandlerException {
    if (in == null) {
        throw new IllegalArgumentException("Input stream can not be 'null'");
    }
    this.in = new DataInputStream(in);
    // Check magic number
    byte[] magicNumber = IOUtil.readBytes(in, MAGIC_NUMBER.length);
    if (!Arrays.equals(magicNumber, MAGIC_NUMBER)) {
        throw new QueryResultParseException("File does not contain a binary RDF table result");
    }
    // Check format version (parser is backward-compatible with version 1 and
    // version 2)
    formatVersion = this.in.readInt();
    if (formatVersion > FORMAT_VERSION && formatVersion < 1) {
        throw new QueryResultParseException("Incompatible format version: " + formatVersion);
    }
    if (formatVersion == 2) {
        // read format version 2 FLAG byte (ordered and distinct flags) and
        // ignore them
        this.in.readByte();
    }
    // Read column headers
    int columnCount = this.in.readInt();
    if (columnCount < 0) {
        throw new QueryResultParseException("Illegal column count specified: " + columnCount);
    }
    List<String> columnHeaders = new ArrayList<String>(columnCount);
    for (int i = 0; i < columnCount; i++) {
        columnHeaders.add(readString());
    }
    columnHeaders = Collections.unmodifiableList(columnHeaders);
    if (handler != null) {
        handler.startQueryResult(columnHeaders);
    }
    // Read value tuples
    List<Value> currentTuple = new ArrayList<Value>(columnCount);
    List<Value> previousTuple = Collections.nCopies(columnCount, (Value) null);
    int recordTypeMarker = this.in.readByte();
    while (recordTypeMarker != TABLE_END_RECORD_MARKER) {
        if (recordTypeMarker == ERROR_RECORD_MARKER) {
            processError();
        } else if (recordTypeMarker == NAMESPACE_RECORD_MARKER) {
            processNamespace();
        } else if (recordTypeMarker == EMPTY_ROW_RECORD_MARKER) {
            if (handler != null) {
                handler.handleSolution(EmptyBindingSet.getInstance());
            }
        } else {
            Value value = null;
            switch(recordTypeMarker) {
                case NULL_RECORD_MARKER:
                    // do nothing
                    break;
                case REPEAT_RECORD_MARKER:
                    value = previousTuple.get(currentTuple.size());
                    break;
                case QNAME_RECORD_MARKER:
                    value = readQName();
                    break;
                case URI_RECORD_MARKER:
                    value = readURI();
                    break;
                case BNODE_RECORD_MARKER:
                    value = readBnode();
                    break;
                case PLAIN_LITERAL_RECORD_MARKER:
                case LANG_LITERAL_RECORD_MARKER:
                case DATATYPE_LITERAL_RECORD_MARKER:
                    value = readLiteral(recordTypeMarker);
                    break;
                default:
                    throw new IOException("Unkown record type: " + recordTypeMarker);
            }
            currentTuple.add(value);
            if (currentTuple.size() == columnCount) {
                previousTuple = Collections.unmodifiableList(currentTuple);
                currentTuple = new ArrayList<Value>(columnCount);
                if (handler != null) {
                    handler.handleSolution(new ListBindingSet(columnHeaders, previousTuple));
                }
            }
        }
        recordTypeMarker = this.in.readByte();
    }
    if (handler != null) {
        handler.endQueryResult();
    }
}
Also used : QueryResultParseException(org.eclipse.rdf4j.query.resultio.QueryResultParseException) ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Value(org.eclipse.rdf4j.model.Value)

Aggregations

ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)20 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)6 Value (org.eclipse.rdf4j.model.Value)5 IRI (org.eclipse.rdf4j.model.IRI)3 BindingSet (org.eclipse.rdf4j.query.BindingSet)3 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)2 EmptyBindingSet (org.eclipse.rdf4j.query.impl.EmptyBindingSet)2 IteratingTupleQueryResult (org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult)2 MutableTupleQueryResult (org.eclipse.rdf4j.query.impl.MutableTupleQueryResult)2 CSVReader (com.opencsv.CSVReader)1 BufferedReader (java.io.BufferedReader)1 DataInputStream (java.io.DataInputStream)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 AbstractCloseableIteration (org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration)1