You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2016/04/29 18:32:53 UTC
[05/25] spark git commit: [SPARK-14987][SQL] inline hive-service
(cli) into sql/hive-thriftserver
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
new file mode 100644
index 0000000..47a582e
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hive.service.cli.thrift.TColumn;
+import org.apache.hive.service.cli.thrift.TRow;
+import org.apache.hive.service.cli.thrift.TRowSet;
+
+/**
+ * ColumnBasedSet.
+ */
+public class ColumnBasedSet implements RowSet {
+
+ private long startOffset;
+
+ private final Type[] types; // non-null only for writing (server-side)
+ private final List<Column> columns;
+
+ public ColumnBasedSet(TableSchema schema) {
+ types = schema.toTypes();
+ columns = new ArrayList<Column>();
+ for (ColumnDescriptor colDesc : schema.getColumnDescriptors()) {
+ columns.add(new Column(colDesc.getType()));
+ }
+ }
+
+ public ColumnBasedSet(TRowSet tRowSet) {
+ types = null;
+ columns = new ArrayList<Column>();
+ for (TColumn tvalue : tRowSet.getColumns()) {
+ columns.add(new Column(tvalue));
+ }
+ startOffset = tRowSet.getStartRowOffset();
+ }
+
+ private ColumnBasedSet(Type[] types, List<Column> columns, long startOffset) {
+ this.types = types;
+ this.columns = columns;
+ this.startOffset = startOffset;
+ }
+
+ @Override
+ public ColumnBasedSet addRow(Object[] fields) {
+ for (int i = 0; i < fields.length; i++) {
+ columns.get(i).addValue(types[i], fields[i]);
+ }
+ return this;
+ }
+
+ public List<Column> getColumns() {
+ return columns;
+ }
+
+ @Override
+ public int numColumns() {
+ return columns.size();
+ }
+
+ @Override
+ public int numRows() {
+ return columns.isEmpty() ? 0 : columns.get(0).size();
+ }
+
+ @Override
+ public ColumnBasedSet extractSubset(int maxRows) {
+ int numRows = Math.min(numRows(), maxRows);
+
+ List<Column> subset = new ArrayList<Column>();
+ for (int i = 0; i < columns.size(); i++) {
+ subset.add(columns.get(i).extractSubset(0, numRows));
+ }
+ ColumnBasedSet result = new ColumnBasedSet(types, subset, startOffset);
+ startOffset += numRows;
+ return result;
+ }
+
+ @Override
+ public long getStartOffset() {
+ return startOffset;
+ }
+
+ @Override
+ public void setStartOffset(long startOffset) {
+ this.startOffset = startOffset;
+ }
+
+ public TRowSet toTRowSet() {
+ TRowSet tRowSet = new TRowSet(startOffset, new ArrayList<TRow>());
+ for (int i = 0; i < columns.size(); i++) {
+ tRowSet.addToColumns(columns.get(i).toTColumn());
+ }
+ return tRowSet;
+ }
+
+ @Override
+ public Iterator<Object[]> iterator() {
+ return new Iterator<Object[]>() {
+
+ private int index;
+ private final Object[] convey = new Object[numColumns()];
+
+ @Override
+ public boolean hasNext() {
+ return index < numRows();
+ }
+
+ @Override
+ public Object[] next() {
+ for (int i = 0; i < columns.size(); i++) {
+ convey[i] = columns.get(i).get(index);
+ }
+ index++;
+ return convey;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
+ };
+ }
+
+ public Object[] fill(int index, Object[] convey) {
+ for (int i = 0; i < columns.size(); i++) {
+ convey[i] = columns.get(i).get(index);
+ }
+ return convey;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnDescriptor.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnDescriptor.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnDescriptor.java
new file mode 100644
index 0000000..f0bbf14
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnDescriptor.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hive.service.cli.thrift.TColumnDesc;
+
+
+/**
+ * ColumnDescriptor.
+ *
+ */
+public class ColumnDescriptor {
+ private final String name;
+ private final String comment;
+ private final TypeDescriptor type;
+ // ordinal position of this column in the schema
+ private final int position;
+
+ public ColumnDescriptor(String name, String comment, TypeDescriptor type, int position) {
+ this.name = name;
+ this.comment = comment;
+ this.type = type;
+ this.position = position;
+ }
+
+ public ColumnDescriptor(TColumnDesc tColumnDesc) {
+ name = tColumnDesc.getColumnName();
+ comment = tColumnDesc.getComment();
+ type = new TypeDescriptor(tColumnDesc.getTypeDesc());
+ position = tColumnDesc.getPosition();
+ }
+
+ public ColumnDescriptor(FieldSchema column, int position) {
+ name = column.getName();
+ comment = column.getComment();
+ type = new TypeDescriptor(column.getType());
+ this.position = position;
+ }
+
+ public static ColumnDescriptor newPrimitiveColumnDescriptor(String name, String comment, Type type, int position) {
+ // Current usage looks like it's only for metadata columns, but if that changes then
+ // this method may need to require a type qualifiers aruments.
+ return new ColumnDescriptor(name, comment, new TypeDescriptor(type), position);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public TypeDescriptor getTypeDescriptor() {
+ return type;
+ }
+
+ public int getOrdinalPosition() {
+ return position;
+ }
+
+ public TColumnDesc toTColumnDesc() {
+ TColumnDesc tColumnDesc = new TColumnDesc();
+ tColumnDesc.setColumnName(name);
+ tColumnDesc.setComment(comment);
+ tColumnDesc.setTypeDesc(type.toTTypeDesc());
+ tColumnDesc.setPosition(position);
+ return tColumnDesc;
+ }
+
+ public Type getType() {
+ return type.getType();
+ }
+
+ public boolean isPrimitive() {
+ return type.getType().isPrimitiveType();
+ }
+
+ public String getTypeName() {
+ return type.getTypeName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnValue.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnValue.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnValue.java
new file mode 100644
index 0000000..40144cf
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ColumnValue.java
@@ -0,0 +1,307 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Timestamp;
+
+import org.apache.hadoop.hive.common.type.HiveChar;
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
+import org.apache.hadoop.hive.common.type.HiveVarchar;
+import org.apache.hive.service.cli.thrift.TBoolValue;
+import org.apache.hive.service.cli.thrift.TByteValue;
+import org.apache.hive.service.cli.thrift.TColumnValue;
+import org.apache.hive.service.cli.thrift.TDoubleValue;
+import org.apache.hive.service.cli.thrift.TI16Value;
+import org.apache.hive.service.cli.thrift.TI32Value;
+import org.apache.hive.service.cli.thrift.TI64Value;
+import org.apache.hive.service.cli.thrift.TStringValue;
+
+/**
+ * Protocols before HIVE_CLI_SERVICE_PROTOCOL_V6 (used by RowBasedSet)
+ *
+ */
+public class ColumnValue {
+
+ private static TColumnValue booleanValue(Boolean value) {
+ TBoolValue tBoolValue = new TBoolValue();
+ if (value != null) {
+ tBoolValue.setValue(value);
+ }
+ return TColumnValue.boolVal(tBoolValue);
+ }
+
+ private static TColumnValue byteValue(Byte value) {
+ TByteValue tByteValue = new TByteValue();
+ if (value != null) {
+ tByteValue.setValue(value);
+ }
+ return TColumnValue.byteVal(tByteValue);
+ }
+
+ private static TColumnValue shortValue(Short value) {
+ TI16Value tI16Value = new TI16Value();
+ if (value != null) {
+ tI16Value.setValue(value);
+ }
+ return TColumnValue.i16Val(tI16Value);
+ }
+
+ private static TColumnValue intValue(Integer value) {
+ TI32Value tI32Value = new TI32Value();
+ if (value != null) {
+ tI32Value.setValue(value);
+ }
+ return TColumnValue.i32Val(tI32Value);
+ }
+
+ private static TColumnValue longValue(Long value) {
+ TI64Value tI64Value = new TI64Value();
+ if (value != null) {
+ tI64Value.setValue(value);
+ }
+ return TColumnValue.i64Val(tI64Value);
+ }
+
+ private static TColumnValue floatValue(Float value) {
+ TDoubleValue tDoubleValue = new TDoubleValue();
+ if (value != null) {
+ tDoubleValue.setValue(value);
+ }
+ return TColumnValue.doubleVal(tDoubleValue);
+ }
+
+ private static TColumnValue doubleValue(Double value) {
+ TDoubleValue tDoubleValue = new TDoubleValue();
+ if (value != null) {
+ tDoubleValue.setValue(value);
+ }
+ return TColumnValue.doubleVal(tDoubleValue);
+ }
+
+ private static TColumnValue stringValue(String value) {
+ TStringValue tStringValue = new TStringValue();
+ if (value != null) {
+ tStringValue.setValue(value);
+ }
+ return TColumnValue.stringVal(tStringValue);
+ }
+
+ private static TColumnValue stringValue(HiveChar value) {
+ TStringValue tStringValue = new TStringValue();
+ if (value != null) {
+ tStringValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStringValue);
+ }
+
+ private static TColumnValue stringValue(HiveVarchar value) {
+ TStringValue tStringValue = new TStringValue();
+ if (value != null) {
+ tStringValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStringValue);
+ }
+
+ private static TColumnValue dateValue(Date value) {
+ TStringValue tStringValue = new TStringValue();
+ if (value != null) {
+ tStringValue.setValue(value.toString());
+ }
+ return new TColumnValue(TColumnValue.stringVal(tStringValue));
+ }
+
+ private static TColumnValue timestampValue(Timestamp value) {
+ TStringValue tStringValue = new TStringValue();
+ if (value != null) {
+ tStringValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStringValue);
+ }
+
+ private static TColumnValue stringValue(HiveDecimal value) {
+ TStringValue tStrValue = new TStringValue();
+ if (value != null) {
+ tStrValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStrValue);
+ }
+
+ private static TColumnValue stringValue(HiveIntervalYearMonth value) {
+ TStringValue tStrValue = new TStringValue();
+ if (value != null) {
+ tStrValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStrValue);
+ }
+
+ private static TColumnValue stringValue(HiveIntervalDayTime value) {
+ TStringValue tStrValue = new TStringValue();
+ if (value != null) {
+ tStrValue.setValue(value.toString());
+ }
+ return TColumnValue.stringVal(tStrValue);
+ }
+
+ public static TColumnValue toTColumnValue(Type type, Object value) {
+ switch (type) {
+ case BOOLEAN_TYPE:
+ return booleanValue((Boolean)value);
+ case TINYINT_TYPE:
+ return byteValue((Byte)value);
+ case SMALLINT_TYPE:
+ return shortValue((Short)value);
+ case INT_TYPE:
+ return intValue((Integer)value);
+ case BIGINT_TYPE:
+ return longValue((Long)value);
+ case FLOAT_TYPE:
+ return floatValue((Float)value);
+ case DOUBLE_TYPE:
+ return doubleValue((Double)value);
+ case STRING_TYPE:
+ return stringValue((String)value);
+ case CHAR_TYPE:
+ return stringValue((HiveChar)value);
+ case VARCHAR_TYPE:
+ return stringValue((HiveVarchar)value);
+ case DATE_TYPE:
+ return dateValue((Date)value);
+ case TIMESTAMP_TYPE:
+ return timestampValue((Timestamp)value);
+ case INTERVAL_YEAR_MONTH_TYPE:
+ return stringValue((HiveIntervalYearMonth) value);
+ case INTERVAL_DAY_TIME_TYPE:
+ return stringValue((HiveIntervalDayTime) value);
+ case DECIMAL_TYPE:
+ return stringValue(((HiveDecimal)value));
+ case BINARY_TYPE:
+ return stringValue((String)value);
+ case ARRAY_TYPE:
+ case MAP_TYPE:
+ case STRUCT_TYPE:
+ case UNION_TYPE:
+ case USER_DEFINED_TYPE:
+ return stringValue((String)value);
+ default:
+ return null;
+ }
+ }
+
+ private static Boolean getBooleanValue(TBoolValue tBoolValue) {
+ if (tBoolValue.isSetValue()) {
+ return tBoolValue.isValue();
+ }
+ return null;
+ }
+
+ private static Byte getByteValue(TByteValue tByteValue) {
+ if (tByteValue.isSetValue()) {
+ return tByteValue.getValue();
+ }
+ return null;
+ }
+
+ private static Short getShortValue(TI16Value tI16Value) {
+ if (tI16Value.isSetValue()) {
+ return tI16Value.getValue();
+ }
+ return null;
+ }
+
+ private static Integer getIntegerValue(TI32Value tI32Value) {
+ if (tI32Value.isSetValue()) {
+ return tI32Value.getValue();
+ }
+ return null;
+ }
+
+ private static Long getLongValue(TI64Value tI64Value) {
+ if (tI64Value.isSetValue()) {
+ return tI64Value.getValue();
+ }
+ return null;
+ }
+
+ private static Double getDoubleValue(TDoubleValue tDoubleValue) {
+ if (tDoubleValue.isSetValue()) {
+ return tDoubleValue.getValue();
+ }
+ return null;
+ }
+
+ private static String getStringValue(TStringValue tStringValue) {
+ if (tStringValue.isSetValue()) {
+ return tStringValue.getValue();
+ }
+ return null;
+ }
+
+ private static Date getDateValue(TStringValue tStringValue) {
+ if (tStringValue.isSetValue()) {
+ return Date.valueOf(tStringValue.getValue());
+ }
+ return null;
+ }
+
+ private static Timestamp getTimestampValue(TStringValue tStringValue) {
+ if (tStringValue.isSetValue()) {
+ return Timestamp.valueOf(tStringValue.getValue());
+ }
+ return null;
+ }
+
+ private static byte[] getBinaryValue(TStringValue tString) {
+ if (tString.isSetValue()) {
+ return tString.getValue().getBytes();
+ }
+ return null;
+ }
+
+ private static BigDecimal getBigDecimalValue(TStringValue tStringValue) {
+ if (tStringValue.isSetValue()) {
+ return new BigDecimal(tStringValue.getValue());
+ }
+ return null;
+ }
+
+ public static Object toColumnValue(TColumnValue value) {
+ TColumnValue._Fields field = value.getSetField();
+ switch (field) {
+ case BOOL_VAL:
+ return getBooleanValue(value.getBoolVal());
+ case BYTE_VAL:
+ return getByteValue(value.getByteVal());
+ case I16_VAL:
+ return getShortValue(value.getI16Val());
+ case I32_VAL:
+ return getIntegerValue(value.getI32Val());
+ case I64_VAL:
+ return getLongValue(value.getI64Val());
+ case DOUBLE_VAL:
+ return getDoubleValue(value.getDoubleVal());
+ case STRING_VAL:
+ return getStringValue(value.getStringVal());
+ }
+ throw new IllegalArgumentException("never");
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java
new file mode 100644
index 0000000..9cad5be
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hive.service.auth.HiveAuthFactory;
+
+
+/**
+ * EmbeddedCLIServiceClient.
+ *
+ */
+public class EmbeddedCLIServiceClient extends CLIServiceClient {
+ private final ICLIService cliService;
+
+ public EmbeddedCLIServiceClient(ICLIService cliService) {
+ this.cliService = cliService;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#openSession(java.lang.String, java.lang.String, java.util.Map)
+ */
+ @Override
+ public SessionHandle openSession(String username, String password,
+ Map<String, String> configuration) throws HiveSQLException {
+ return cliService.openSession(username, password, configuration);
+ }
+
+ @Override
+ public SessionHandle openSessionWithImpersonation(String username, String password,
+ Map<String, String> configuration, String delegationToken) throws HiveSQLException {
+ throw new HiveSQLException("Impersonated session is not supported in the embedded mode");
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#closeSession(org.apache.hive.service.cli.SessionHandle)
+ */
+ @Override
+ public void closeSession(SessionHandle sessionHandle) throws HiveSQLException {
+ cliService.closeSession(sessionHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getInfo(org.apache.hive.service.cli.SessionHandle, java.util.List)
+ */
+ @Override
+ public GetInfoValue getInfo(SessionHandle sessionHandle, GetInfoType getInfoType)
+ throws HiveSQLException {
+ return cliService.getInfo(sessionHandle, getInfoType);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#executeStatement(org.apache.hive.service.cli.SessionHandle,
+ * java.lang.String, java.util.Map)
+ */
+ @Override
+ public OperationHandle executeStatement(SessionHandle sessionHandle, String statement,
+ Map<String, String> confOverlay) throws HiveSQLException {
+ return cliService.executeStatement(sessionHandle, statement, confOverlay);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#executeStatementAsync(org.apache.hive.service.cli.SessionHandle,
+ * java.lang.String, java.util.Map)
+ */
+ @Override
+ public OperationHandle executeStatementAsync(SessionHandle sessionHandle, String statement,
+ Map<String, String> confOverlay) throws HiveSQLException {
+ return cliService.executeStatementAsync(sessionHandle, statement, confOverlay);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getTypeInfo(org.apache.hive.service.cli.SessionHandle)
+ */
+ @Override
+ public OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException {
+ return cliService.getTypeInfo(sessionHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getCatalogs(org.apache.hive.service.cli.SessionHandle)
+ */
+ @Override
+ public OperationHandle getCatalogs(SessionHandle sessionHandle) throws HiveSQLException {
+ return cliService.getCatalogs(sessionHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getSchemas(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String)
+ */
+ @Override
+ public OperationHandle getSchemas(SessionHandle sessionHandle, String catalogName,
+ String schemaName) throws HiveSQLException {
+ return cliService.getSchemas(sessionHandle, catalogName, schemaName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getTables(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.util.List)
+ */
+ @Override
+ public OperationHandle getTables(SessionHandle sessionHandle, String catalogName,
+ String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException {
+ return cliService.getTables(sessionHandle, catalogName, schemaName, tableName, tableTypes);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getTableTypes(org.apache.hive.service.cli.SessionHandle)
+ */
+ @Override
+ public OperationHandle getTableTypes(SessionHandle sessionHandle) throws HiveSQLException {
+ return cliService.getTableTypes(sessionHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getColumns(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public OperationHandle getColumns(SessionHandle sessionHandle, String catalogName,
+ String schemaName, String tableName, String columnName) throws HiveSQLException {
+ return cliService.getColumns(sessionHandle, catalogName, schemaName, tableName, columnName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getFunctions(org.apache.hive.service.cli.SessionHandle, java.lang.String)
+ */
+ @Override
+ public OperationHandle getFunctions(SessionHandle sessionHandle,
+ String catalogName, String schemaName, String functionName)
+ throws HiveSQLException {
+ return cliService.getFunctions(sessionHandle, catalogName, schemaName, functionName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
+ */
+ @Override
+ public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
+ return cliService.getOperationStatus(opHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#cancelOperation(org.apache.hive.service.cli.OperationHandle)
+ */
+ @Override
+ public void cancelOperation(OperationHandle opHandle) throws HiveSQLException {
+ cliService.cancelOperation(opHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#closeOperation(org.apache.hive.service.cli.OperationHandle)
+ */
+ @Override
+ public void closeOperation(OperationHandle opHandle) throws HiveSQLException {
+ cliService.closeOperation(opHandle);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hive.service.cli.CLIServiceClient#getResultSetMetadata(org.apache.hive.service.cli.OperationHandle)
+ */
+ @Override
+ public TableSchema getResultSetMetadata(OperationHandle opHandle) throws HiveSQLException {
+ return cliService.getResultSetMetadata(opHandle);
+ }
+
+ @Override
+ public RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation,
+ long maxRows, FetchType fetchType) throws HiveSQLException {
+ return cliService.fetchResults(opHandle, orientation, maxRows, fetchType);
+ }
+
+
+ @Override
+ public String getDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String owner, String renewer) throws HiveSQLException {
+ return cliService.getDelegationToken(sessionHandle, authFactory, owner, renewer);
+ }
+
+ @Override
+ public void cancelDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String tokenStr) throws HiveSQLException {
+ cliService.cancelDelegationToken(sessionHandle, authFactory, tokenStr);
+ }
+
+ @Override
+ public void renewDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String tokenStr) throws HiveSQLException {
+ cliService.renewDelegationToken(sessionHandle, authFactory, tokenStr);
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchOrientation.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchOrientation.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchOrientation.java
new file mode 100644
index 0000000..ffa6f2e
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchOrientation.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TFetchOrientation;
+
+/**
+ * FetchOrientation.
+ *
+ */
+public enum FetchOrientation {
+ FETCH_NEXT(TFetchOrientation.FETCH_NEXT),
+ FETCH_PRIOR(TFetchOrientation.FETCH_PRIOR),
+ FETCH_RELATIVE(TFetchOrientation.FETCH_RELATIVE),
+ FETCH_ABSOLUTE(TFetchOrientation.FETCH_ABSOLUTE),
+ FETCH_FIRST(TFetchOrientation.FETCH_FIRST),
+ FETCH_LAST(TFetchOrientation.FETCH_LAST);
+
+ private TFetchOrientation tFetchOrientation;
+
+ FetchOrientation(TFetchOrientation tFetchOrientation) {
+ this.tFetchOrientation = tFetchOrientation;
+ }
+
+ public static FetchOrientation getFetchOrientation(TFetchOrientation tFetchOrientation) {
+ for (FetchOrientation fetchOrientation : values()) {
+ if (tFetchOrientation.equals(fetchOrientation.toTFetchOrientation())) {
+ return fetchOrientation;
+ }
+ }
+ // TODO: Should this really default to FETCH_NEXT?
+ return FETCH_NEXT;
+ }
+
+ public TFetchOrientation toTFetchOrientation() {
+ return tFetchOrientation;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchType.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchType.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchType.java
new file mode 100644
index 0000000..a8e7fe1
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/FetchType.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+/**
+ * FetchType indicates the type of fetchResults request.
+ * It maps the TFetchType, which is generated from Thrift interface.
+ */
+public enum FetchType {
+ QUERY_OUTPUT((short)0),
+ LOG((short)1);
+
+ private final short tFetchType;
+
+ FetchType(short tFetchType) {
+ this.tFetchType = tFetchType;
+ }
+
+ public static FetchType getFetchType(short tFetchType) {
+ for (FetchType fetchType : values()) {
+ if (tFetchType == fetchType.toTFetchType()) {
+ return fetchType;
+ }
+ }
+ return QUERY_OUTPUT;
+ }
+
+ public short toTFetchType() {
+ return tFetchType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoType.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoType.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoType.java
new file mode 100644
index 0000000..8dd33a8
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoType.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TGetInfoType;
+
+/**
+ * GetInfoType.
+ *
+ */
+public enum GetInfoType {
+ CLI_MAX_DRIVER_CONNECTIONS(TGetInfoType.CLI_MAX_DRIVER_CONNECTIONS),
+ CLI_MAX_CONCURRENT_ACTIVITIES(TGetInfoType.CLI_MAX_CONCURRENT_ACTIVITIES),
+ CLI_DATA_SOURCE_NAME(TGetInfoType.CLI_DATA_SOURCE_NAME),
+ CLI_FETCH_DIRECTION(TGetInfoType.CLI_FETCH_DIRECTION),
+ CLI_SERVER_NAME(TGetInfoType.CLI_SERVER_NAME),
+ CLI_SEARCH_PATTERN_ESCAPE(TGetInfoType.CLI_SEARCH_PATTERN_ESCAPE),
+ CLI_DBMS_NAME(TGetInfoType.CLI_DBMS_NAME),
+ CLI_DBMS_VER(TGetInfoType.CLI_DBMS_VER),
+ CLI_ACCESSIBLE_TABLES(TGetInfoType.CLI_ACCESSIBLE_TABLES),
+ CLI_ACCESSIBLE_PROCEDURES(TGetInfoType.CLI_ACCESSIBLE_PROCEDURES),
+ CLI_CURSOR_COMMIT_BEHAVIOR(TGetInfoType.CLI_CURSOR_COMMIT_BEHAVIOR),
+ CLI_DATA_SOURCE_READ_ONLY(TGetInfoType.CLI_DATA_SOURCE_READ_ONLY),
+ CLI_DEFAULT_TXN_ISOLATION(TGetInfoType.CLI_DEFAULT_TXN_ISOLATION),
+ CLI_IDENTIFIER_CASE(TGetInfoType.CLI_IDENTIFIER_CASE),
+ CLI_IDENTIFIER_QUOTE_CHAR(TGetInfoType.CLI_IDENTIFIER_QUOTE_CHAR),
+ CLI_MAX_COLUMN_NAME_LEN(TGetInfoType.CLI_MAX_COLUMN_NAME_LEN),
+ CLI_MAX_CURSOR_NAME_LEN(TGetInfoType.CLI_MAX_CURSOR_NAME_LEN),
+ CLI_MAX_SCHEMA_NAME_LEN(TGetInfoType.CLI_MAX_SCHEMA_NAME_LEN),
+ CLI_MAX_CATALOG_NAME_LEN(TGetInfoType.CLI_MAX_CATALOG_NAME_LEN),
+ CLI_MAX_TABLE_NAME_LEN(TGetInfoType.CLI_MAX_TABLE_NAME_LEN),
+ CLI_SCROLL_CONCURRENCY(TGetInfoType.CLI_SCROLL_CONCURRENCY),
+ CLI_TXN_CAPABLE(TGetInfoType.CLI_TXN_CAPABLE),
+ CLI_USER_NAME(TGetInfoType.CLI_USER_NAME),
+ CLI_TXN_ISOLATION_OPTION(TGetInfoType.CLI_TXN_ISOLATION_OPTION),
+ CLI_INTEGRITY(TGetInfoType.CLI_INTEGRITY),
+ CLI_GETDATA_EXTENSIONS(TGetInfoType.CLI_GETDATA_EXTENSIONS),
+ CLI_NULL_COLLATION(TGetInfoType.CLI_NULL_COLLATION),
+ CLI_ALTER_TABLE(TGetInfoType.CLI_ALTER_TABLE),
+ CLI_ORDER_BY_COLUMNS_IN_SELECT(TGetInfoType.CLI_ORDER_BY_COLUMNS_IN_SELECT),
+ CLI_SPECIAL_CHARACTERS(TGetInfoType.CLI_SPECIAL_CHARACTERS),
+ CLI_MAX_COLUMNS_IN_GROUP_BY(TGetInfoType.CLI_MAX_COLUMNS_IN_GROUP_BY),
+ CLI_MAX_COLUMNS_IN_INDEX(TGetInfoType.CLI_MAX_COLUMNS_IN_INDEX),
+ CLI_MAX_COLUMNS_IN_ORDER_BY(TGetInfoType.CLI_MAX_COLUMNS_IN_ORDER_BY),
+ CLI_MAX_COLUMNS_IN_SELECT(TGetInfoType.CLI_MAX_COLUMNS_IN_SELECT),
+ CLI_MAX_COLUMNS_IN_TABLE(TGetInfoType.CLI_MAX_COLUMNS_IN_TABLE),
+ CLI_MAX_INDEX_SIZE(TGetInfoType.CLI_MAX_INDEX_SIZE),
+ CLI_MAX_ROW_SIZE(TGetInfoType.CLI_MAX_ROW_SIZE),
+ CLI_MAX_STATEMENT_LEN(TGetInfoType.CLI_MAX_STATEMENT_LEN),
+ CLI_MAX_TABLES_IN_SELECT(TGetInfoType.CLI_MAX_TABLES_IN_SELECT),
+ CLI_MAX_USER_NAME_LEN(TGetInfoType.CLI_MAX_USER_NAME_LEN),
+ CLI_OJ_CAPABILITIES(TGetInfoType.CLI_OJ_CAPABILITIES),
+
+ CLI_XOPEN_CLI_YEAR(TGetInfoType.CLI_XOPEN_CLI_YEAR),
+ CLI_CURSOR_SENSITIVITY(TGetInfoType.CLI_CURSOR_SENSITIVITY),
+ CLI_DESCRIBE_PARAMETER(TGetInfoType.CLI_DESCRIBE_PARAMETER),
+ CLI_CATALOG_NAME(TGetInfoType.CLI_CATALOG_NAME),
+ CLI_COLLATION_SEQ(TGetInfoType.CLI_COLLATION_SEQ),
+ CLI_MAX_IDENTIFIER_LEN(TGetInfoType.CLI_MAX_IDENTIFIER_LEN);
+
+ private final TGetInfoType tInfoType;
+
+ GetInfoType(TGetInfoType tInfoType) {
+ this.tInfoType = tInfoType;
+ }
+
+ public static GetInfoType getGetInfoType(TGetInfoType tGetInfoType) {
+ for (GetInfoType infoType : values()) {
+ if (tGetInfoType.equals(infoType.tInfoType)) {
+ return infoType;
+ }
+ }
+ throw new IllegalArgumentException("Unrecognized Thrift TGetInfoType value: " + tGetInfoType);
+ }
+
+ public TGetInfoType toTGetInfoType() {
+ return tInfoType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoValue.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoValue.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoValue.java
new file mode 100644
index 0000000..ba92ff4
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/GetInfoValue.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TGetInfoValue;
+
+/**
+ * GetInfoValue.
+ *
+ */
+public class GetInfoValue {
+ private String stringValue = null;
+ private short shortValue;
+ private int intValue;
+ private long longValue;
+
+ public GetInfoValue(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ public GetInfoValue(short shortValue) {
+ this.shortValue = shortValue;
+ }
+
+ public GetInfoValue(int intValue) {
+ this.intValue = intValue;
+ }
+
+ public GetInfoValue(long longValue) {
+ this.longValue = longValue;
+ }
+
+ public GetInfoValue(TGetInfoValue tGetInfoValue) {
+ switch (tGetInfoValue.getSetField()) {
+ case STRING_VALUE:
+ stringValue = tGetInfoValue.getStringValue();
+ break;
+ default:
+ throw new IllegalArgumentException("Unreconigzed TGetInfoValue");
+ }
+ }
+
+ public TGetInfoValue toTGetInfoValue() {
+ TGetInfoValue tInfoValue = new TGetInfoValue();
+ if (stringValue != null) {
+ tInfoValue.setStringValue(stringValue);
+ }
+ return tInfoValue;
+ }
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ public short getShortValue() {
+ return shortValue;
+ }
+
+ public int getIntValue() {
+ return intValue;
+ }
+
+ public long getLongValue() {
+ return longValue;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/Handle.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/Handle.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/Handle.java
new file mode 100644
index 0000000..cf3427a
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/Handle.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.THandleIdentifier;
+
+
+
+
+public abstract class Handle {
+
+ private final HandleIdentifier handleId;
+
+ public Handle() {
+ handleId = new HandleIdentifier();
+ }
+
+ public Handle(HandleIdentifier handleId) {
+ this.handleId = handleId;
+ }
+
+ public Handle(THandleIdentifier tHandleIdentifier) {
+ this.handleId = new HandleIdentifier(tHandleIdentifier);
+ }
+
+ public HandleIdentifier getHandleIdentifier() {
+ return handleId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((handleId == null) ? 0 : handleId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof Handle)) {
+ return false;
+ }
+ Handle other = (Handle) obj;
+ if (handleId == null) {
+ if (other.handleId != null) {
+ return false;
+ }
+ } else if (!handleId.equals(other.handleId)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public abstract String toString();
+
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HandleIdentifier.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HandleIdentifier.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HandleIdentifier.java
new file mode 100644
index 0000000..4dc80da
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HandleIdentifier.java
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.apache.hive.service.cli.thrift.THandleIdentifier;
+
+/**
+ * HandleIdentifier.
+ *
+ */
+public class HandleIdentifier {
+ private final UUID publicId;
+ private final UUID secretId;
+
+ public HandleIdentifier() {
+ publicId = UUID.randomUUID();
+ secretId = UUID.randomUUID();
+ }
+
+ public HandleIdentifier(UUID publicId, UUID secretId) {
+ this.publicId = publicId;
+ this.secretId = secretId;
+ }
+
+ public HandleIdentifier(THandleIdentifier tHandleId) {
+ ByteBuffer bb = ByteBuffer.wrap(tHandleId.getGuid());
+ this.publicId = new UUID(bb.getLong(), bb.getLong());
+ bb = ByteBuffer.wrap(tHandleId.getSecret());
+ this.secretId = new UUID(bb.getLong(), bb.getLong());
+ }
+
+ public UUID getPublicId() {
+ return publicId;
+ }
+
+ public UUID getSecretId() {
+ return secretId;
+ }
+
+ public THandleIdentifier toTHandleIdentifier() {
+ byte[] guid = new byte[16];
+ byte[] secret = new byte[16];
+ ByteBuffer guidBB = ByteBuffer.wrap(guid);
+ ByteBuffer secretBB = ByteBuffer.wrap(secret);
+ guidBB.putLong(publicId.getMostSignificantBits());
+ guidBB.putLong(publicId.getLeastSignificantBits());
+ secretBB.putLong(secretId.getMostSignificantBits());
+ secretBB.putLong(secretId.getLeastSignificantBits());
+ return new THandleIdentifier(ByteBuffer.wrap(guid), ByteBuffer.wrap(secret));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((publicId == null) ? 0 : publicId.hashCode());
+ result = prime * result + ((secretId == null) ? 0 : secretId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof HandleIdentifier)) {
+ return false;
+ }
+ HandleIdentifier other = (HandleIdentifier) obj;
+ if (publicId == null) {
+ if (other.publicId != null) {
+ return false;
+ }
+ } else if (!publicId.equals(other.publicId)) {
+ return false;
+ }
+ if (secretId == null) {
+ if (other.secretId != null) {
+ return false;
+ }
+ } else if (!secretId.equals(other.secretId)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return publicId.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HiveSQLException.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HiveSQLException.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HiveSQLException.java
new file mode 100644
index 0000000..1334dde
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/HiveSQLException.java
@@ -0,0 +1,248 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hive.service.cli.thrift.TStatus;
+import org.apache.hive.service.cli.thrift.TStatusCode;
+
+/**
+ * HiveSQLException.
+ *
+ */
+public class HiveSQLException extends SQLException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6095254671958748094L;
+
+ /**
+ *
+ */
+ public HiveSQLException() {
+ super();
+ }
+
+ /**
+ * @param reason
+ */
+ public HiveSQLException(String reason) {
+ super(reason);
+ }
+
+ /**
+ * @param cause
+ */
+ public HiveSQLException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param reason
+ * @param sqlState
+ */
+ public HiveSQLException(String reason, String sqlState) {
+ super(reason, sqlState);
+ }
+
+ /**
+ * @param reason
+ * @param cause
+ */
+ public HiveSQLException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
+
+ /**
+ * @param reason
+ * @param sqlState
+ * @param vendorCode
+ */
+ public HiveSQLException(String reason, String sqlState, int vendorCode) {
+ super(reason, sqlState, vendorCode);
+ }
+
+ /**
+ * @param reason
+ * @param sqlState
+ * @param cause
+ */
+ public HiveSQLException(String reason, String sqlState, Throwable cause) {
+ super(reason, sqlState, cause);
+ }
+
+ /**
+ * @param reason
+ * @param sqlState
+ * @param vendorCode
+ * @param cause
+ */
+ public HiveSQLException(String reason, String sqlState, int vendorCode, Throwable cause) {
+ super(reason, sqlState, vendorCode, cause);
+ }
+
+ public HiveSQLException(TStatus status) {
+ // TODO: set correct vendorCode field
+ super(status.getErrorMessage(), status.getSqlState(), status.getErrorCode());
+ if (status.getInfoMessages() != null) {
+ initCause(toCause(status.getInfoMessages()));
+ }
+ }
+
+ /**
+ * Converts current object to a {@link TStatus} object
+ * @return a {@link TStatus} object
+ */
+ public TStatus toTStatus() {
+ // TODO: convert sqlState, etc.
+ TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS);
+ tStatus.setSqlState(getSQLState());
+ tStatus.setErrorCode(getErrorCode());
+ tStatus.setErrorMessage(getMessage());
+ tStatus.setInfoMessages(toString(this));
+ return tStatus;
+ }
+
+ /**
+ * Converts the specified {@link Exception} object into a {@link TStatus} object
+ * @param e a {@link Exception} object
+ * @return a {@link TStatus} object
+ */
+ public static TStatus toTStatus(Exception e) {
+ if (e instanceof HiveSQLException) {
+ return ((HiveSQLException)e).toTStatus();
+ }
+ TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS);
+ tStatus.setErrorMessage(e.getMessage());
+ tStatus.setInfoMessages(toString(e));
+ return tStatus;
+ }
+
+ /**
+ * Converts a {@link Throwable} object into a flattened list of texts including its stack trace
+ * and the stack traces of the nested causes.
+ * @param ex a {@link Throwable} object
+ * @return a flattened list of texts including the {@link Throwable} object's stack trace
+ * and the stack traces of the nested causes.
+ */
+ public static List<String> toString(Throwable ex) {
+ return toString(ex, null);
+ }
+
+ private static List<String> toString(Throwable cause, StackTraceElement[] parent) {
+ StackTraceElement[] trace = cause.getStackTrace();
+ int m = trace.length - 1;
+ if (parent != null) {
+ int n = parent.length - 1;
+ while (m >= 0 && n >= 0 && trace[m].equals(parent[n])) {
+ m--; n--;
+ }
+ }
+ List<String> detail = enroll(cause, trace, m);
+ cause = cause.getCause();
+ if (cause != null) {
+ detail.addAll(toString(cause, trace));
+ }
+ return detail;
+ }
+
+ private static List<String> enroll(Throwable ex, StackTraceElement[] trace, int max) {
+ List<String> details = new ArrayList<String>();
+ StringBuilder builder = new StringBuilder();
+ builder.append('*').append(ex.getClass().getName()).append(':');
+ builder.append(ex.getMessage()).append(':');
+ builder.append(trace.length).append(':').append(max);
+ details.add(builder.toString());
+ for (int i = 0; i <= max; i++) {
+ builder.setLength(0);
+ builder.append(trace[i].getClassName()).append(':');
+ builder.append(trace[i].getMethodName()).append(':');
+ String fileName = trace[i].getFileName();
+ builder.append(fileName == null ? "" : fileName).append(':');
+ builder.append(trace[i].getLineNumber());
+ details.add(builder.toString());
+ }
+ return details;
+ }
+
+ /**
+ * Converts a flattened list of texts including the stack trace and the stack
+ * traces of the nested causes into a {@link Throwable} object.
+ * @param details a flattened list of texts including the stack trace and the stack
+ * traces of the nested causes
+ * @return a {@link Throwable} object
+ */
+ public static Throwable toCause(List<String> details) {
+ return toStackTrace(details, null, 0);
+ }
+
+ private static Throwable toStackTrace(List<String> details, StackTraceElement[] parent, int index) {
+ String detail = details.get(index++);
+ if (!detail.startsWith("*")) {
+ return null; // should not be happened. ignore remaining
+ }
+ int i1 = detail.indexOf(':');
+ int i3 = detail.lastIndexOf(':');
+ int i2 = detail.substring(0, i3).lastIndexOf(':');
+ String exceptionClass = detail.substring(1, i1);
+ String exceptionMessage = detail.substring(i1 + 1, i2);
+ Throwable ex = newInstance(exceptionClass, exceptionMessage);
+
+ Integer length = Integer.valueOf(detail.substring(i2 + 1, i3));
+ Integer unique = Integer.valueOf(detail.substring(i3 + 1));
+
+ int i = 0;
+ StackTraceElement[] trace = new StackTraceElement[length];
+ for (; i <= unique; i++) {
+ detail = details.get(index++);
+ int j1 = detail.indexOf(':');
+ int j3 = detail.lastIndexOf(':');
+ int j2 = detail.substring(0, j3).lastIndexOf(':');
+ String className = detail.substring(0, j1);
+ String methodName = detail.substring(j1 + 1, j2);
+ String fileName = detail.substring(j2 + 1, j3);
+ if (fileName.isEmpty()) {
+ fileName = null;
+ }
+ int lineNumber = Integer.valueOf(detail.substring(j3 + 1));
+ trace[i] = new StackTraceElement(className, methodName, fileName, lineNumber);
+ }
+ int common = trace.length - i;
+ if (common > 0) {
+ System.arraycopy(parent, parent.length - common, trace, trace.length - common, common);
+ }
+ if (details.size() > index) {
+ ex.initCause(toStackTrace(details, trace, index));
+ }
+ ex.setStackTrace(trace);
+ return ex;
+ }
+
+ private static Throwable newInstance(String className, String message) {
+ try {
+ return (Throwable)Class.forName(className).getConstructor(String.class).newInstance(message);
+ } catch (Exception e) {
+ return new RuntimeException(className + ":" + message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ICLIService.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ICLIService.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ICLIService.java
new file mode 100644
index 0000000..c9cc1f4
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/ICLIService.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hive.service.cli;
+
+import java.util.List;
+import java.util.Map;
+
+
+
+
+import org.apache.hive.service.auth.HiveAuthFactory;
+
+public interface ICLIService {
+
+ SessionHandle openSession(String username, String password,
+ Map<String, String> configuration)
+ throws HiveSQLException;
+
+ SessionHandle openSessionWithImpersonation(String username, String password,
+ Map<String, String> configuration, String delegationToken)
+ throws HiveSQLException;
+
+ void closeSession(SessionHandle sessionHandle)
+ throws HiveSQLException;
+
+ GetInfoValue getInfo(SessionHandle sessionHandle, GetInfoType infoType)
+ throws HiveSQLException;
+
+ OperationHandle executeStatement(SessionHandle sessionHandle, String statement,
+ Map<String, String> confOverlay)
+ throws HiveSQLException;
+
+ OperationHandle executeStatementAsync(SessionHandle sessionHandle,
+ String statement, Map<String, String> confOverlay)
+ throws HiveSQLException;
+
+ OperationHandle getTypeInfo(SessionHandle sessionHandle)
+ throws HiveSQLException;
+
+ OperationHandle getCatalogs(SessionHandle sessionHandle)
+ throws HiveSQLException;
+
+ OperationHandle getSchemas(SessionHandle sessionHandle,
+ String catalogName, String schemaName)
+ throws HiveSQLException;
+
+ OperationHandle getTables(SessionHandle sessionHandle,
+ String catalogName, String schemaName, String tableName, List<String> tableTypes)
+ throws HiveSQLException;
+
+ OperationHandle getTableTypes(SessionHandle sessionHandle)
+ throws HiveSQLException;
+
+ OperationHandle getColumns(SessionHandle sessionHandle,
+ String catalogName, String schemaName, String tableName, String columnName)
+ throws HiveSQLException;
+
+ OperationHandle getFunctions(SessionHandle sessionHandle,
+ String catalogName, String schemaName, String functionName)
+ throws HiveSQLException;
+
+ OperationStatus getOperationStatus(OperationHandle opHandle)
+ throws HiveSQLException;
+
+ void cancelOperation(OperationHandle opHandle)
+ throws HiveSQLException;
+
+ void closeOperation(OperationHandle opHandle)
+ throws HiveSQLException;
+
+ TableSchema getResultSetMetadata(OperationHandle opHandle)
+ throws HiveSQLException;
+
+ RowSet fetchResults(OperationHandle opHandle)
+ throws HiveSQLException;
+
+ RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation,
+ long maxRows, FetchType fetchType) throws HiveSQLException;
+
+ String getDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String owner, String renewer) throws HiveSQLException;
+
+ void cancelDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String tokenStr) throws HiveSQLException;
+
+ void renewDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory,
+ String tokenStr) throws HiveSQLException;
+
+
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationHandle.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationHandle.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationHandle.java
new file mode 100644
index 0000000..5426e28
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationHandle.java
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TOperationHandle;
+import org.apache.hive.service.cli.thrift.TProtocolVersion;
+
+public class OperationHandle extends Handle {
+
+ private final OperationType opType;
+ private final TProtocolVersion protocol;
+ private boolean hasResultSet = false;
+
+ public OperationHandle(OperationType opType, TProtocolVersion protocol) {
+ super();
+ this.opType = opType;
+ this.protocol = protocol;
+ }
+
+ // dummy handle for ThriftCLIService
+ public OperationHandle(TOperationHandle tOperationHandle) {
+ this(tOperationHandle, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1);
+ }
+
+ public OperationHandle(TOperationHandle tOperationHandle, TProtocolVersion protocol) {
+ super(tOperationHandle.getOperationId());
+ this.opType = OperationType.getOperationType(tOperationHandle.getOperationType());
+ this.hasResultSet = tOperationHandle.isHasResultSet();
+ this.protocol = protocol;
+ }
+
+ public OperationType getOperationType() {
+ return opType;
+ }
+
+ public void setHasResultSet(boolean hasResultSet) {
+ this.hasResultSet = hasResultSet;
+ }
+
+ public boolean hasResultSet() {
+ return hasResultSet;
+ }
+
+ public TOperationHandle toTOperationHandle() {
+ TOperationHandle tOperationHandle = new TOperationHandle();
+ tOperationHandle.setOperationId(getHandleIdentifier().toTHandleIdentifier());
+ tOperationHandle.setOperationType(opType.toTOperationType());
+ tOperationHandle.setHasResultSet(hasResultSet);
+ return tOperationHandle;
+ }
+
+ public TProtocolVersion getProtocolVersion() {
+ return protocol;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((opType == null) ? 0 : opType.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof OperationHandle)) {
+ return false;
+ }
+ OperationHandle other = (OperationHandle) obj;
+ if (opType != other.opType) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "OperationHandle [opType=" + opType + ", getHandleIdentifier()=" + getHandleIdentifier()
+ + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationState.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationState.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationState.java
new file mode 100644
index 0000000..51ffb40
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationState.java
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TOperationState;
+
+/**
+ * OperationState.
+ *
+ */
+public enum OperationState {
+ INITIALIZED(TOperationState.INITIALIZED_STATE, false),
+ RUNNING(TOperationState.RUNNING_STATE, false),
+ FINISHED(TOperationState.FINISHED_STATE, true),
+ CANCELED(TOperationState.CANCELED_STATE, true),
+ CLOSED(TOperationState.CLOSED_STATE, true),
+ ERROR(TOperationState.ERROR_STATE, true),
+ UNKNOWN(TOperationState.UKNOWN_STATE, false),
+ PENDING(TOperationState.PENDING_STATE, false);
+
+ private final TOperationState tOperationState;
+ private final boolean terminal;
+
+ OperationState(TOperationState tOperationState, boolean terminal) {
+ this.tOperationState = tOperationState;
+ this.terminal = terminal;
+ }
+
+ // must be sync with TOperationState in order
+ public static OperationState getOperationState(TOperationState tOperationState) {
+ return OperationState.values()[tOperationState.getValue()];
+ }
+
+ public static void validateTransition(OperationState oldState,
+ OperationState newState)
+ throws HiveSQLException {
+ switch (oldState) {
+ case INITIALIZED:
+ switch (newState) {
+ case PENDING:
+ case RUNNING:
+ case CANCELED:
+ case CLOSED:
+ return;
+ }
+ break;
+ case PENDING:
+ switch (newState) {
+ case RUNNING:
+ case FINISHED:
+ case CANCELED:
+ case ERROR:
+ case CLOSED:
+ return;
+ }
+ break;
+ case RUNNING:
+ switch (newState) {
+ case FINISHED:
+ case CANCELED:
+ case ERROR:
+ case CLOSED:
+ return;
+ }
+ break;
+ case FINISHED:
+ case CANCELED:
+ case ERROR:
+ if (OperationState.CLOSED.equals(newState)) {
+ return;
+ }
+ default:
+ // fall-through
+ }
+ throw new HiveSQLException("Illegal Operation state transition " +
+ "from " + oldState + " to " + newState);
+ }
+
+ public void validateTransition(OperationState newState)
+ throws HiveSQLException {
+ validateTransition(this, newState);
+ }
+
+ public TOperationState toTOperationState() {
+ return tOperationState;
+ }
+
+ public boolean isTerminal() {
+ return terminal;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationStatus.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationStatus.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationStatus.java
new file mode 100644
index 0000000..e45b828
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationStatus.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+/**
+ * OperationStatus
+ *
+ */
+public class OperationStatus {
+
+ private final OperationState state;
+ private final HiveSQLException operationException;
+
+ public OperationStatus(OperationState state, HiveSQLException operationException) {
+ this.state = state;
+ this.operationException = operationException;
+ }
+
+ public OperationState getState() {
+ return state;
+ }
+
+ public HiveSQLException getOperationException() {
+ return operationException;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationType.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationType.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationType.java
new file mode 100644
index 0000000..429d9a4
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/OperationType.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TOperationType;
+
+/**
+ * OperationType.
+ *
+ */
+public enum OperationType {
+
+ UNKNOWN_OPERATION(TOperationType.UNKNOWN),
+ EXECUTE_STATEMENT(TOperationType.EXECUTE_STATEMENT),
+ GET_TYPE_INFO(TOperationType.GET_TYPE_INFO),
+ GET_CATALOGS(TOperationType.GET_CATALOGS),
+ GET_SCHEMAS(TOperationType.GET_SCHEMAS),
+ GET_TABLES(TOperationType.GET_TABLES),
+ GET_TABLE_TYPES(TOperationType.GET_TABLE_TYPES),
+ GET_COLUMNS(TOperationType.GET_COLUMNS),
+ GET_FUNCTIONS(TOperationType.GET_FUNCTIONS);
+
+ private TOperationType tOperationType;
+
+ OperationType(TOperationType tOpType) {
+ this.tOperationType = tOpType;
+ }
+
+ public static OperationType getOperationType(TOperationType tOperationType) {
+ // TODO: replace this with a Map?
+ for (OperationType opType : values()) {
+ if (tOperationType.equals(opType.tOperationType)) {
+ return opType;
+ }
+ }
+ return OperationType.UNKNOWN_OPERATION;
+ }
+
+ public TOperationType toTOperationType() {
+ return tOperationType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/PatternOrIdentifier.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/PatternOrIdentifier.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/PatternOrIdentifier.java
new file mode 100644
index 0000000..6e4d43f
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/PatternOrIdentifier.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+/**
+ * PatternOrIdentifier.
+ *
+ */
+public class PatternOrIdentifier {
+
+ boolean isPattern = false;
+ String text;
+
+ public PatternOrIdentifier(String tpoi) {
+ text = tpoi;
+ isPattern = false;
+ }
+
+ public boolean isPattern() {
+ return isPattern;
+ }
+
+ public boolean isIdentifier() {
+ return !isPattern;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowBasedSet.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowBasedSet.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowBasedSet.java
new file mode 100644
index 0000000..a0ee210
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowBasedSet.java
@@ -0,0 +1,140 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hive.service.cli.thrift.TColumnValue;
+import org.apache.hive.service.cli.thrift.TRow;
+import org.apache.hive.service.cli.thrift.TRowSet;
+
+/**
+ * RowBasedSet
+ */
+public class RowBasedSet implements RowSet {
+
+ private long startOffset;
+
+ private final Type[] types; // non-null only for writing (server-side)
+ private final RemovableList<TRow> rows;
+
+ public RowBasedSet(TableSchema schema) {
+ types = schema.toTypes();
+ rows = new RemovableList<TRow>();
+ }
+
+ public RowBasedSet(TRowSet tRowSet) {
+ types = null;
+ rows = new RemovableList<TRow>(tRowSet.getRows());
+ startOffset = tRowSet.getStartRowOffset();
+ }
+
+ private RowBasedSet(Type[] types, List<TRow> rows, long startOffset) {
+ this.types = types;
+ this.rows = new RemovableList<TRow>(rows);
+ this.startOffset = startOffset;
+ }
+
+ @Override
+ public RowBasedSet addRow(Object[] fields) {
+ TRow tRow = new TRow();
+ for (int i = 0; i < fields.length; i++) {
+ tRow.addToColVals(ColumnValue.toTColumnValue(types[i], fields[i]));
+ }
+ rows.add(tRow);
+ return this;
+ }
+
+ @Override
+ public int numColumns() {
+ return rows.isEmpty() ? 0 : rows.get(0).getColVals().size();
+ }
+
+ @Override
+ public int numRows() {
+ return rows.size();
+ }
+
+ public RowBasedSet extractSubset(int maxRows) {
+ int numRows = Math.min(numRows(), maxRows);
+ RowBasedSet result = new RowBasedSet(types, rows.subList(0, numRows), startOffset);
+ rows.removeRange(0, numRows);
+ startOffset += numRows;
+ return result;
+ }
+
+ public long getStartOffset() {
+ return startOffset;
+ }
+
+ public void setStartOffset(long startOffset) {
+ this.startOffset = startOffset;
+ }
+
+ public int getSize() {
+ return rows.size();
+ }
+
+ public TRowSet toTRowSet() {
+ TRowSet tRowSet = new TRowSet();
+ tRowSet.setStartRowOffset(startOffset);
+ tRowSet.setRows(new ArrayList<TRow>(rows));
+ return tRowSet;
+ }
+
+ @Override
+ public Iterator<Object[]> iterator() {
+ return new Iterator<Object[]>() {
+
+ final Iterator<TRow> iterator = rows.iterator();
+ final Object[] convey = new Object[numColumns()];
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public Object[] next() {
+ TRow row = iterator.next();
+ List<TColumnValue> values = row.getColVals();
+ for (int i = 0; i < values.size(); i++) {
+ convey[i] = ColumnValue.toColumnValue(values.get(i));
+ }
+ return convey;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
+ };
+ }
+
+ private static class RemovableList<E> extends ArrayList<E> {
+ public RemovableList() { super(); }
+ public RemovableList(List<E> rows) { super(rows); }
+ @Override
+ public void removeRange(int fromIndex, int toIndex) {
+ super.removeRange(fromIndex, toIndex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSet.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSet.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSet.java
new file mode 100644
index 0000000..ab0787e
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSet.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TRowSet;
+
+public interface RowSet extends Iterable<Object[]> {
+
+ RowSet addRow(Object[] fields);
+
+ RowSet extractSubset(int maxRows);
+
+ int numColumns();
+
+ int numRows();
+
+ long getStartOffset();
+
+ void setStartOffset(long startOffset);
+
+ TRowSet toTRowSet();
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSetFactory.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSetFactory.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSetFactory.java
new file mode 100644
index 0000000..e8f68ea
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/RowSetFactory.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import org.apache.hive.service.cli.thrift.TProtocolVersion;
+import org.apache.hive.service.cli.thrift.TRowSet;
+
+import static org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6;
+
+public class RowSetFactory {
+
+ public static RowSet create(TableSchema schema, TProtocolVersion version) {
+ if (version.getValue() >= HIVE_CLI_SERVICE_PROTOCOL_V6.getValue()) {
+ return new ColumnBasedSet(schema);
+ }
+ return new RowBasedSet(schema);
+ }
+
+ public static RowSet create(TRowSet results, TProtocolVersion version) {
+ if (version.getValue() >= HIVE_CLI_SERVICE_PROTOCOL_V6.getValue()) {
+ return new ColumnBasedSet(results);
+ }
+ return new RowBasedSet(results);
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/SessionHandle.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/SessionHandle.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/SessionHandle.java
new file mode 100644
index 0000000..52e0ad4
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/SessionHandle.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.util.UUID;
+
+import org.apache.hive.service.cli.thrift.TProtocolVersion;
+import org.apache.hive.service.cli.thrift.TSessionHandle;
+
+
+/**
+ * SessionHandle.
+ *
+ */
+public class SessionHandle extends Handle {
+
+ private final TProtocolVersion protocol;
+
+ public SessionHandle(TProtocolVersion protocol) {
+ this.protocol = protocol;
+ }
+
+ // dummy handle for ThriftCLIService
+ public SessionHandle(TSessionHandle tSessionHandle) {
+ this(tSessionHandle, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1);
+ }
+
+ public SessionHandle(TSessionHandle tSessionHandle, TProtocolVersion protocol) {
+ super(tSessionHandle.getSessionId());
+ this.protocol = protocol;
+ }
+
+ public UUID getSessionId() {
+ return getHandleIdentifier().getPublicId();
+ }
+
+ public TSessionHandle toTSessionHandle() {
+ TSessionHandle tSessionHandle = new TSessionHandle();
+ tSessionHandle.setSessionId(getHandleIdentifier().toTHandleIdentifier());
+ return tSessionHandle;
+ }
+
+ public TProtocolVersion getProtocolVersion() {
+ return protocol;
+ }
+
+ @Override
+ public String toString() {
+ return "SessionHandle [" + getHandleIdentifier() + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/spark/blob/7feeb82c/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/TableSchema.java
----------------------------------------------------------------------
diff --git a/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/TableSchema.java b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/TableSchema.java
new file mode 100644
index 0000000..ee019bc
--- /dev/null
+++ b/sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/TableSchema.java
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.service.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Schema;
+import org.apache.hive.service.cli.thrift.TColumnDesc;
+import org.apache.hive.service.cli.thrift.TTableSchema;
+
+/**
+ * TableSchema.
+ *
+ */
+public class TableSchema {
+ private final List<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
+
+ public TableSchema() {
+ }
+
+ public TableSchema(int numColumns) {
+ // TODO: remove this constructor
+ }
+
+ public TableSchema(TTableSchema tTableSchema) {
+ for (TColumnDesc tColumnDesc : tTableSchema.getColumns()) {
+ columns.add(new ColumnDescriptor(tColumnDesc));
+ }
+ }
+
+ public TableSchema(List<FieldSchema> fieldSchemas) {
+ int pos = 1;
+ for (FieldSchema field : fieldSchemas) {
+ columns.add(new ColumnDescriptor(field, pos++));
+ }
+ }
+
+ public TableSchema(Schema schema) {
+ this(schema.getFieldSchemas());
+ }
+
+ public List<ColumnDescriptor> getColumnDescriptors() {
+ return new ArrayList<ColumnDescriptor>(columns);
+ }
+
+ public ColumnDescriptor getColumnDescriptorAt(int pos) {
+ return columns.get(pos);
+ }
+
+ public int getSize() {
+ return columns.size();
+ }
+
+ public void clear() {
+ columns.clear();
+ }
+
+
+ public TTableSchema toTTableSchema() {
+ TTableSchema tTableSchema = new TTableSchema();
+ for (ColumnDescriptor col : columns) {
+ tTableSchema.addToColumns(col.toTColumnDesc());
+ }
+ return tTableSchema;
+ }
+
+ public Type[] toTypes() {
+ Type[] types = new Type[columns.size()];
+ for (int i = 0; i < types.length; i++) {
+ types[i] = columns.get(i).getType();
+ }
+ return types;
+ }
+
+ public TableSchema addPrimitiveColumn(String columnName, Type columnType, String columnComment) {
+ columns.add(ColumnDescriptor.newPrimitiveColumnDescriptor(columnName, columnComment, columnType, columns.size() + 1));
+ return this;
+ }
+
+ public TableSchema addStringColumn(String columnName, String columnComment) {
+ columns.add(ColumnDescriptor.newPrimitiveColumnDescriptor(columnName, columnComment, Type.STRING_TYPE, columns.size() + 1));
+ return this;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org