Example usage for java.sql JDBCType DOUBLE

List of usage examples for java.sql JDBCType DOUBLE

Introduction

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

Prototype

JDBCType DOUBLE

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

Click Source Link

Document

Identifies the generic SQL type DOUBLE .

Usage

From source file:com.thinkbiganalytics.discovery.util.ParserHelperTest.java

@Test

public void testSqlTypeToHiveType() throws Exception {
    assertEquals(ParserHelper.sqlTypeToHiveType(JDBCType.DOUBLE), "double");
}

From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java

/**
 * Derive the corresponding data type from sample values
 *
 * @param values a list of string values
 * @return the JDBC data type//from w  w w. j a  va2  s . c o m
 */
public static JDBCType deriveJDBCDataType(List<String> values) {

    JDBCType guess = null;
    if (values != null) {
        for (String v : values) {
            if (!StringUtils.isEmpty(v)) {
                JDBCType currentPass;
                try {
                    Integer.parseInt(v);
                    currentPass = JDBCType.INTEGER;
                } catch (NumberFormatException e) {
                    try {
                        Double.parseDouble(v);
                        currentPass = JDBCType.DOUBLE;
                    } catch (NumberFormatException ex) {
                        // return immediately for non-numeric case
                        return JDBCType.VARCHAR;
                    }
                }
                // If a double is encountered, use that type
                if (guess == null || currentPass == JDBCType.DOUBLE) {
                    guess = currentPass;
                }
            }
        }
    }
    return (guess == null ? JDBCType.VARCHAR : guess);
}

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  .  ja  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)));
}