org.apache.hive.service.cli.RowSet Java Examples
The following examples show how to use
org.apache.hive.service.cli.RowSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveTester.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void assertFunctionCall(String functionCallString, Object expectedOutputData, Object expectedOutputType) { String query = "SELECT " + functionCallString; try { // Execute the SQL statement and fetch the result OperationHandle handle = _client.executeStatement(_sessionHandle, query, null); if (handle.hasResultSet()) { RowSet rowSet = _client.fetchResults(handle); if (rowSet.numRows() > 1 || rowSet.numColumns() > 1) { throw new RuntimeException( "Expected 1 row and 1 column in query output. Received " + rowSet.numRows() + " rows and " + rowSet.numColumns() + " columns.\nQuery: \"" + query + "\""); } Object[] row = rowSet.iterator().next(); Object result = row[0]; Assert.assertEquals(result, expectedOutputData, "UDF output does not match"); // Get the output data type and convert them to TypeInfo to compare ColumnDescriptor outputColumnDescriptor = _client.getResultSetMetadata(handle).getColumnDescriptors().get(0); Assert.assertEquals(TypeInfoUtils.getTypeInfoFromTypeString(outputColumnDescriptor.getTypeName().toLowerCase()), TypeInfoUtils.getTypeInfoFromObjectInspector((ObjectInspector) expectedOutputType), "UDF output type does not match"); } else { throw new RuntimeException("Query did not return any rows. Query: \"" + query + "\""); } } catch (HiveSQLException e) { throw fetchUnderlyingException(e); } }
Example #2
Source File: HiveEmbeddedServer2.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
@Override public List<String> execute(String cmd) throws Exception { if (cmd.toUpperCase().startsWith("ADD JAR")) { // skip the jar since we're running in local mode System.out.println("Skipping ADD JAR in local/embedded mode"); return Collections.emptyList(); } // remove bogus configuration config.set("columns.comments", ""); CLIService client = getServiceClientInternal(); SessionHandle sh = null; try { Map<String, String> opConf = new HashMap<String, String>(); sh = client.openSession("anonymous", "anonymous", opConf); OperationHandle oh = client.executeStatement(sh, cmd, opConf); if (oh.hasResultSet()) { RowSet rows = client.fetchResults(oh); List<String> result = new ArrayList<String>(rows.numRows()); for (Object[] objects : rows) { result.add(StringUtils.concatenate(objects, ",")); } return result; } return Collections.emptyList(); } finally { if (sh != null) { client.closeSession(sh); } } }
Example #3
Source File: HiveServerContainer.java From HiveRunner with Apache License 2.0 | 5 votes |
public List<Object[]> executeStatement(String hiveql) { try { OperationHandle handle = client.executeStatement(sessionHandle, hiveql, new HashMap<>()); List<Object[]> resultSet = new ArrayList<>(); if (handle.hasResultSet()) { /* * fetchResults will by default return 100 rows per fetch (hive 14). For big result sets we need to continuously fetch the result set until all * rows are fetched. */ RowSet rowSet; while ((rowSet = client.fetchResults(handle)) != null && rowSet.numRows() > 0) { for (Object[] row : rowSet) { resultSet.add(row.clone()); } } } LOGGER.debug("ResultSet:\n" + Joiner.on("\n").join(Iterables.transform(resultSet, new Function<Object[], String>() { @Nullable @Override public String apply(@Nullable Object[] objects) { return Joiner.on(", ").useForNull("null").join(objects); } }))); return resultSet; } catch (HiveSQLException e) { throw new IllegalArgumentException("Failed to executeQuery Hive query " + hiveql + ": " + e.getMessage(), e); } }