Example usage for java.sql JDBCType BIGINT

List of usage examples for java.sql JDBCType BIGINT

Introduction

In this page you can find the example usage for java.sql JDBCType BIGINT.

Prototype

JDBCType BIGINT

To view the source code for java.sql JDBCType BIGINT.

Click Source Link

Document

Identifies the generic SQL type BIGINT .

Usage

From source file:org.elasticsearch.xpack.qa.sql.multinode.RestSqlMultinodeIT.java

private void assertCount(RestClient client, int count) throws IOException {
    Map<String, Object> expected = new HashMap<>();
    String mode = randomMode();// w  ww. j  a v  a2  s .co  m
    expected.put("columns", singletonList(columnInfo(mode, "COUNT(1)", "long", JDBCType.BIGINT, 20)));
    expected.put("rows", singletonList(singletonList(count)));

    Request request = new Request("POST", "/_xpack/sql");
    if (false == mode.isEmpty()) {
        request.addParameter("mode", mode);
    }
    request.setJsonEntity("{\"query\": \"SELECT COUNT(*) FROM test\"}");
    Map<String, Object> actual = responseToMap(client.performRequest(request));

    if (false == expected.equals(actual)) {
        NotEqualMessageBuilder message = new NotEqualMessageBuilder();
        message.compareMaps(actual, expected);
        fail("Response does not match:\n" + message.toString());
    }
}

From source file:org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.java

public void testNextPage() throws IOException {
    Request request = new Request("POST", "/test/test/_bulk");
    request.addParameter("refresh", "true");
    String mode = randomMode();//from ww w  . j av a  2s  .c  o m
    StringBuilder bulk = new StringBuilder();
    for (int i = 0; i < 20; i++) {
        bulk.append("{\"index\":{\"_id\":\"" + i + "\"}}\n");
        bulk.append("{\"text\":\"text" + i + "\", \"number\":" + i + "}\n");
    }
    request.setJsonEntity(bulk.toString());
    client().performRequest(request);

    String sqlRequest = "{\"query\":\"" + "   SELECT text, number, SQRT(number) AS s, SCORE()"
            + "     FROM test" + " ORDER BY number, SCORE()\", " + "\"mode\":\"" + mode + "\", "
            + "\"fetch_size\":2}";

    String cursor = null;
    for (int i = 0; i < 20; i += 2) {
        Map<String, Object> response;
        if (i == 0) {
            response = runSql(mode, new StringEntity(sqlRequest, ContentType.APPLICATION_JSON));
        } else {
            response = runSql(mode,
                    new StringEntity("{\"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON));
        }

        Map<String, Object> expected = new HashMap<>();
        if (i == 0) {
            expected.put("columns",
                    Arrays.asList(columnInfo(mode, "text", "text", JDBCType.VARCHAR, 0),
                            columnInfo(mode, "number", "long", JDBCType.BIGINT, 20),
                            columnInfo(mode, "s", "double", JDBCType.DOUBLE, 25),
                            columnInfo(mode, "SCORE()", "float", JDBCType.REAL, 15)));
        }
        expected.put("rows", Arrays.asList(Arrays.asList("text" + i, i, Math.sqrt(i), 1.0),
                Arrays.asList("text" + (i + 1), i + 1, Math.sqrt(i + 1), 1.0)));
        cursor = (String) response.remove("cursor");
        assertResponse(expected, response);
        assertNotNull(cursor);
    }
    Map<String, Object> expected = new HashMap<>();
    expected.put("rows", emptyList());
    assertResponse(expected,
            runSql(mode, new StringEntity("{ \"cursor\":\"" + cursor + "\"}", ContentType.APPLICATION_JSON)));
}

From source file:org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.java

public void testScoreWithFieldNamedScore() throws IOException {
    Request request = new Request("POST", "/test/test/_bulk");
    request.addParameter("refresh", "true");
    String mode = randomMode();/*w  ww .j a v a2 s . com*/
    StringBuilder bulk = new StringBuilder();
    bulk.append("{\"index\":{\"_id\":\"1\"}}\n");
    bulk.append("{\"name\":\"test\", \"score\":10}\n");
    request.setJsonEntity(bulk.toString());
    client().performRequest(request);

    Map<String, Object> expected = new HashMap<>();
    expected.put("columns",
            Arrays.asList(columnInfo(mode, "name", "text", JDBCType.VARCHAR, 0),
                    columnInfo(mode, "score", "long", JDBCType.BIGINT, 20),
                    columnInfo(mode, "SCORE()", "float", JDBCType.REAL, 15)));
    expected.put("rows", singletonList(Arrays.asList("test", 10, 1.0)));

    assertResponse(expected, runSql(mode, "SELECT *, SCORE() FROM test ORDER BY SCORE()"));
    assertResponse(expected, runSql(mode, "SELECT name, \\\"score\\\", SCORE() FROM test ORDER BY SCORE()"));
}