openlink / virtuoso-opensource

Virtuoso is a high-performance and scalable Multi-Model RDBMS, Data Integration Middleware, Linked Data Deployment, and HTTP Application Server Platform
https://vos.openlinksw.com
Other
855 stars 211 forks source link

JDBC Select DISTINCT #326

Open jgager opened 9 years ago

jgager commented 9 years ago

When I run the following in using JDBC, the DISTINCT selection is not applied:

        String sparql = "sparql SELECT DISTINCT(?uri) {VALUES ?uri {<a><b><c><a>}}";
        dataSource = new VirtuosoConnectionPoolDataSource();
        dataSource.setServerName("server.ip.address");
        dataSource.setPortNumber(1111);
        dataSource.setUser("dba");
        dataSource.setPassword("dba");
        dataSource.setCharset("UTF-8");
        Statement s = null;
        ResultSet rs = null;
        Connection connection = null;
        try {
            connection = dataSource.getConnection();
            s = connection.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            rs = s.executeQuery(sparql);
            int count = 0;
            while (rs.next()) {
                count++;
                System.out.println(rs.getString(1));
            }
            System.out
                    .println("Found " + count + " records");
        } catch (SQLException sqe) {
            System.err.println(sqe.getMessage());
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                    rs = null;
                } catch (SQLException e) {
                    // ignore
                }
            }
            if (s != null) {
                try {
                    s.close();
                    s = null;
                } catch (SQLException e) {
                    // ignore
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                    connection = null;
                } catch (SQLException e) {
                    // ignore
                }
            }
        }

The result will be:

a
b
c
a
Found 4 records

Note that changing the result set type to forward only:

            s = connection.createStatement(
                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

works properly:

a
b
c
Found 3 records
HughWilliams commented 9 years ago

I have been able to recreate this issue and reported to development to look into ...