コード例 #1
0
        public void ConstraintBound()
        {
            MemoryTripleStore statements = new MemoryTripleStore();

            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p"), new UriRef("ex:o")));

            SimpleQueryBuilder builder = new SimpleQueryBuilder();

            builder.AddPattern(new Pattern(new UriRef("ex:s"), new UriRef("ex:p"), new Variable("v")));
            builder.AddConstraint(new Constraint(new Bound(new Variable("v"))));
            Query query = builder.GetQuery();

            QuerySqlMapper mapper = new QuerySqlMapper(query, statements);

            string expected =
                "SELECT rn_v.resourceHash rh_v, rn_v.nodeHash nh_v, rn_v.nodeType nt_v, COALESCE(u_v.uri, pl_v.value, l_v.value) val_v, COALESCE(tl_v.value, t_v.value) sub_v " +
                "FROM Statements s1 JOIN ResourceNodes rn_v ON rn_v.resourceHash=s1.objectHash AND rn_v.graphId=s1.graphId " +
                "LEFT OUTER JOIN UriRefs u_v ON rn_v.nodeHash=u_v.hash AND rn_v.nodeType='u' " +
                "LEFT OUTER JOIN PlainLiterals pl_v ON rn_v.nodeHash=pl_v.hash AND rn_v.nodeType='p' " +
                "LEFT OUTER JOIN Languages l_v ON pl_v.languageHash=l_v.hash " +
                "LEFT OUTER JOIN TypedLiterals tl_v ON rn_v.nodehash=tl_v.hash AND rn_v.nodeType='t' " +
                "LEFT OUTER JOIN DataTypes t_v ON tl_v.datatypeHash=t_v.hash " +
                "WHERE s1.subjectHash=" + statements.GetResourceDenotedBy(new UriRef("ex:s")).GetHashCode() +
                " AND s1.predicateHash=" + statements.GetResourceDenotedBy(new UriRef("ex:p")).GetHashCode() +
                " AND s1.graphId=" + statements.GetHashCode() +
                " AND s1.objectHash IS NOT NULL";


            Assert.AreEqual(expected, mapper.Sql);
        }
コード例 #2
0
        public void SingleStatementPlusUnmatchableOptionalStatementWithVariable()
        {
            MemoryTripleStore statements = new MemoryTripleStore();

            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p"), new UriRef("ex:o")));

            SimpleQueryBuilder builder = new SimpleQueryBuilder();

            builder.AddPattern(new Pattern(new Variable("v"), new UriRef("ex:p"), new UriRef("ex:o")));
            builder.AddOptional(new Pattern(new Variable("v"), new UriRef("ex:p2"), new Variable("o")));
            Query query = builder.GetQuery();

            QuerySqlMapper mapper = new QuerySqlMapper(query, statements);

            string expected =
                "SELECT rn_v.resourceHash rh_v, rn_v.nodeHash nh_v, rn_v.nodeType nt_v, u_v.uri val_v, NULL sub_v, NULL rh_o, NULL nh_o, NULL nt_o, NULL val_o, NULL sub_o " +
                "FROM Statements s1 JOIN ResourceNodes rn_v ON rn_v.resourceHash=s1.subjectHash AND rn_v.graphId=s1.graphId " +
                "LEFT OUTER JOIN UriRefs u_v ON rn_v.nodeHash=u_v.hash AND rn_v.nodeType='u' " +
                "WHERE s1.predicateHash=" + statements.GetResourceDenotedBy(new UriRef("ex:p")).GetHashCode() +
                " AND s1.objectHash=" + statements.GetResourceDenotedBy(new UriRef("ex:o")).GetHashCode() +
                " AND s1.graphId=" + statements.GetHashCode();


            Assert.AreEqual(expected, mapper.Sql);
        }
コード例 #3
0
        public void SingleStatementTwoVariables()
        {
            MemoryTripleStore statements = new MemoryTripleStore();

            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p"), new UriRef("ex:o")));

            SimpleQueryBuilder builder = new SimpleQueryBuilder();

            builder.AddPattern(new Pattern(new Variable("s"), new UriRef("ex:p"), new Variable("o")));
            Query query = builder.GetQuery();

            QuerySqlMapper mapper = new QuerySqlMapper(query, statements);

            string expected =
                "SELECT rn_s.resourceHash rh_s, rn_s.nodeHash nh_s, rn_s.nodeType nt_s, u_s.uri val_s, NULL sub_s, rn_o.resourceHash rh_o, rn_o.nodeHash nh_o, rn_o.nodeType nt_o, COALESCE(u_o.uri, pl_o.value, l_o.value) val_o, COALESCE(tl_o.value, t_o.value) sub_o " +
                "FROM Statements s1 JOIN ResourceNodes rn_s ON rn_s.resourceHash=s1.subjectHash AND rn_s.graphId=s1.graphId " +
                "LEFT OUTER JOIN UriRefs u_s ON rn_s.nodeHash=u_s.hash AND rn_s.nodeType='u' " +
                "JOIN ResourceNodes rn_o ON rn_o.resourceHash=s1.objectHash AND rn_o.graphId=s1.graphId " +
                "LEFT OUTER JOIN UriRefs u_o ON rn_o.nodeHash=u_o.hash AND rn_o.nodeType='u' " +
                "LEFT OUTER JOIN PlainLiterals pl_o ON rn_o.nodeHash=pl_o.hash AND rn_o.nodeType='p' " +
                "LEFT OUTER JOIN Languages l_o ON pl_o.languageHash=l_o.hash " +
                "LEFT OUTER JOIN TypedLiterals tl_o ON rn_o.nodehash=tl_o.hash AND rn_o.nodeType='t' " +
                "LEFT OUTER JOIN DataTypes t_o ON tl_o.datatypeHash=t_o.hash " +
                "WHERE s1.predicateHash=" + statements.GetResourceDenotedBy(new UriRef("ex:p")).GetHashCode() +
                " AND s1.graphId=" + statements.GetHashCode();


            Assert.AreEqual(expected, mapper.Sql);
        }
コード例 #4
0
        public void NoPatterns()
        {
            MemoryTripleStore statements = new MemoryTripleStore();

            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p"), new UriRef("ex:o")));

            SimpleQueryBuilder builder = new SimpleQueryBuilder();
            Query query = builder.GetQuery();

            QuerySqlMapper mapper = new QuerySqlMapper(query, statements);

            Assert.AreEqual(false, mapper.IsFeasible);
        }
コード例 #5
0
        public void SingleStatementPlusMultipleOptionalStatementsInOneGroup()
        {
            MemoryTripleStore statements = new MemoryTripleStore();

            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p"), new UriRef("ex:o")));
            statements.Add(new Statement(new UriRef("ex:s"), new UriRef("ex:p2"), new UriRef("ex:o2")));

            SimpleQueryBuilder builder = new SimpleQueryBuilder();

            builder.AddPattern(new Pattern(new Variable("v"), new UriRef("ex:p"), new UriRef("ex:o")));
            builder.AddOptional(new Pattern(new Variable("v"), new Variable("p"), new UriRef("ex:o2")));
            builder.AddOptional(new Pattern(new Variable("v"), new Variable("p"), new UriRef("ex:o")));
            Query query = builder.GetQuery();

            QuerySqlMapper mapper = new QuerySqlMapper(query, statements);

            string expected =
                "SELECT rn_v.resourceHash rh_v, rn_v.nodeHash nh_v, rn_v.nodeType nt_v, u_v.uri val_v, NULL sub_v, rn_p.resourceHash rh_p, rn_p.nodeHash nh_p, rn_p.nodeType nt_p, u_p.uri val_p, NULL sub_p " +
                "FROM Statements s1 " +
                "LEFT OUTER JOIN Statements s2" +
                " ON s2.subjectHash=s1.subjectHash" +
                " AND s2.objectHash=" + statements.GetResourceDenotedBy(new UriRef("ex:o2")).GetHashCode() +
                " AND s2.graphId=" + statements.GetHashCode() +
                " JOIN Statements s3" +
                " ON s3.subjectHash=s2.subjectHash" +
                " AND s3.predicateHash=s2.predicateHash" +
                " AND s3.objectHash=" + statements.GetResourceDenotedBy(new UriRef("ex:o")).GetHashCode() +
                " AND s3.graphId=" + statements.GetHashCode() +
                " JOIN ResourceNodes rn_v ON rn_v.resourceHash=s1.subjectHash AND rn_v.graphId=s1.graphId " +
                "LEFT OUTER JOIN UriRefs u_v ON rn_v.nodeHash=u_v.hash AND rn_v.nodeType='u' " +
                "JOIN ResourceNodes rn_p ON rn_p.resourceHash=s2.predicateHash AND rn_p.graphId=s2.graphId " +
                "LEFT OUTER JOIN UriRefs u_p ON rn_p.nodeHash=u_p.hash AND rn_p.nodeType='u' " +
                "WHERE s1.predicateHash=" + statements.GetResourceDenotedBy(new UriRef("ex:p")).GetHashCode() +
                " AND s1.objectHash=" + statements.GetResourceDenotedBy(new UriRef("ex:o")).GetHashCode() +
                " AND s1.graphId=" + statements.GetHashCode();


            Assert.AreEqual(expected, mapper.Sql);
        }