public Metadata metadata(OperationHandle operationHandle) {
    try {
      List<ColumnMeta> colMeta = new ArrayList<>();
      if (operationHandle.hasResultSet()) {
        TableSchema meta = hiveSession.getResultSetMetadata(operationHandle);
        for (int i = 0; i < meta.getSize(); i++) {
          ColumnDescriptor col = meta.getColumnDescriptorAt(i);
          colMeta.add(new ColumnMeta(col.getName(), col.getTypeName(), col.getType().toJavaSQLType()));
        }
      }
      return new Metadata(colMeta);
    } catch (HiveSQLException e) {
      throw new QueryException(e);
    }
  }
Executing HiveQL from HPL/SQL directly, without JDBC or Thrift.
service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java