List of usage examples for java.sql JDBCType REAL
JDBCType REAL
To view the source code for java.sql JDBCType REAL.
Click Source Link
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 w w w . j a va 2 s .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();/*from www .j av a2 s . c om*/ 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()")); }