List of usage examples for java.sql JDBCType VARCHAR
JDBCType VARCHAR
To view the source code for java.sql JDBCType VARCHAR.
Click Source Link
From source file:org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.java
public void testBasicQuery() throws IOException { index("{\"test\":\"test\"}", "{\"test\":\"test\"}"); Map<String, Object> expected = new HashMap<>(); String mode = randomMode();/*from ww w .j a va 2s. c o m*/ expected.put("columns", singletonList(columnInfo(mode, "test", "text", JDBCType.VARCHAR, 0))); expected.put("rows", Arrays.asList(singletonList("test"), singletonList("test"))); assertResponse(expected, runSql(mode, "SELECT * FROM test")); }
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// ww w . j a va 2s . c om */ 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 w w w . j a v 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:com.thinkbiganalytics.discovery.util.ParserHelper.java
/** * Derive data types//from www . ja v a 2 s . c o m * * @param type the target database platform * @param fields the fields */ public static void deriveDataTypes(TableSchemaType type, List<? extends Field> fields) { for (Field field : fields) { if (StringUtils.isEmpty(field.getDerivedDataType())) { JDBCType jdbcType = JDBCType.VARCHAR; try { if (!StringUtils.isEmpty(field.getNativeDataType())) { jdbcType = JDBCType.valueOf(field.getNativeDataType()); } else { jdbcType = deriveJDBCDataType(field.getSampleValues()); } } catch (IllegalArgumentException e) { log.warn("Unable to convert data type [?] will be converted to VARCHAR", field.getNativeDataType()); } switch (type) { case HIVE: String hiveType = sqlTypeToHiveType(jdbcType); field.setDerivedDataType(hiveType); field.setDataTypeDescriptor(hiveTypeToDescriptor(hiveType)); break; case RDBMS: field.setDerivedDataType(jdbcType.getName()); } } } }
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 w ww . java 2 s. c o m*/ 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()")); }
From source file:com.microsoft.sqlserver.testframework.DBTable.java
/** * /* ww w .j a va 2 s .c o m*/ * @param colNum * @return <code>true</code> if value can be passed as String for the column */ boolean passDataAsString(int colNum) { return (JDBCType.CHAR == getColumn(colNum).getJdbctype() || JDBCType.VARCHAR == getColumn(colNum).getJdbctype() || JDBCType.NCHAR == getColumn(colNum).getJdbctype() || JDBCType.NVARCHAR == getColumn(colNum).getJdbctype() || JDBCType.TIMESTAMP == getColumn(colNum).getJdbctype() || JDBCType.DATE == getColumn(colNum).getJdbctype() || JDBCType.TIME == getColumn(colNum).getJdbctype() || JDBCType.LONGVARCHAR == getColumn(colNum).getJdbctype() || JDBCType.LONGNVARCHAR == getColumn(colNum).getJdbctype()); }
From source file:org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.java
public void testBasicQueryWithFilter() throws IOException { String mode = randomMode();//from w w w.ja v a 2 s .c o m index("{\"test\":\"foo\"}", "{\"test\":\"bar\"}"); Map<String, Object> expected = new HashMap<>(); expected.put("columns", singletonList(columnInfo(mode, "test", "text", JDBCType.VARCHAR, 0))); expected.put("rows", singletonList(singletonList("foo"))); assertResponse(expected, runSql(mode, new StringEntity( "{\"query\":\"SELECT * FROM test\", " + "\"filter\":{\"match\": {\"test\": \"foo\"}}}", ContentType.APPLICATION_JSON))); }
From source file:org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.java
public void testBasicQueryWithParameters() throws IOException { String mode = randomMode();// ww w . j a v a 2 s . c om index("{\"test\":\"foo\"}", "{\"test\":\"bar\"}"); Map<String, Object> expected = new HashMap<>(); expected.put("columns", Arrays.asList(columnInfo(mode, "test", "text", JDBCType.VARCHAR, 0), columnInfo(mode, "param", "integer", JDBCType.INTEGER, 11))); expected.put("rows", singletonList(Arrays.asList("foo", 10))); assertResponse(expected, runSql(mode, new StringEntity("{\"query\":\"SELECT test, ? param FROM test WHERE test = ?\", " + "\"params\":[{\"type\": \"integer\", \"value\": 10}, {\"type\": \"keyword\", \"value\": \"foo\"}]}", ContentType.APPLICATION_JSON))); }