0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 package org.apache.hive.service.cli.operation;
0020
0021 import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType;
0022 import org.apache.hadoop.hive.serde2.thrift.Type;
0023 import org.apache.hive.service.cli.FetchOrientation;
0024 import org.apache.hive.service.cli.HiveSQLException;
0025 import org.apache.hive.service.cli.OperationState;
0026 import org.apache.hive.service.cli.OperationType;
0027 import org.apache.hive.service.cli.RowSet;
0028 import org.apache.hive.service.cli.RowSetFactory;
0029 import org.apache.hive.service.cli.TableSchema;
0030 import org.apache.hive.service.cli.session.HiveSession;
0031
0032
0033
0034
0035
0036 public class GetTypeInfoOperation extends MetadataOperation {
0037
0038 private static final TableSchema RESULT_SET_SCHEMA = new TableSchema()
0039 .addPrimitiveColumn("TYPE_NAME", Type.STRING_TYPE,
0040 "Type name")
0041 .addPrimitiveColumn("DATA_TYPE", Type.INT_TYPE,
0042 "SQL data type from java.sql.Types")
0043 .addPrimitiveColumn("PRECISION", Type.INT_TYPE,
0044 "Maximum precision")
0045 .addPrimitiveColumn("LITERAL_PREFIX", Type.STRING_TYPE,
0046 "Prefix used to quote a literal (may be null)")
0047 .addPrimitiveColumn("LITERAL_SUFFIX", Type.STRING_TYPE,
0048 "Suffix used to quote a literal (may be null)")
0049 .addPrimitiveColumn("CREATE_PARAMS", Type.STRING_TYPE,
0050 "Parameters used in creating the type (may be null)")
0051 .addPrimitiveColumn("NULLABLE", Type.SMALLINT_TYPE,
0052 "Can you use NULL for this type")
0053 .addPrimitiveColumn("CASE_SENSITIVE", Type.BOOLEAN_TYPE,
0054 "Is it case sensitive")
0055 .addPrimitiveColumn("SEARCHABLE", Type.SMALLINT_TYPE,
0056 "Can you use \"WHERE\" based on this type")
0057 .addPrimitiveColumn("UNSIGNED_ATTRIBUTE", Type.BOOLEAN_TYPE,
0058 "Is it unsigned")
0059 .addPrimitiveColumn("FIXED_PREC_SCALE", Type.BOOLEAN_TYPE,
0060 "Can it be a money value")
0061 .addPrimitiveColumn("AUTO_INCREMENT", Type.BOOLEAN_TYPE,
0062 "Can it be used for an auto-increment value")
0063 .addPrimitiveColumn("LOCAL_TYPE_NAME", Type.STRING_TYPE,
0064 "Localized version of type name (may be null)")
0065 .addPrimitiveColumn("MINIMUM_SCALE", Type.SMALLINT_TYPE,
0066 "Minimum scale supported")
0067 .addPrimitiveColumn("MAXIMUM_SCALE", Type.SMALLINT_TYPE,
0068 "Maximum scale supported")
0069 .addPrimitiveColumn("SQL_DATA_TYPE", Type.INT_TYPE,
0070 "Unused")
0071 .addPrimitiveColumn("SQL_DATETIME_SUB", Type.INT_TYPE,
0072 "Unused")
0073 .addPrimitiveColumn("NUM_PREC_RADIX", Type.INT_TYPE,
0074 "Usually 2 or 10");
0075
0076 protected final RowSet rowSet;
0077
0078 protected GetTypeInfoOperation(HiveSession parentSession) {
0079 super(parentSession, OperationType.GET_TYPE_INFO);
0080 rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion(), false);
0081 }
0082
0083 @Override
0084 public void runInternal() throws HiveSQLException {
0085 setState(OperationState.RUNNING);
0086 if (isAuthV2Enabled()) {
0087 authorizeMetaGets(HiveOperationType.GET_TYPEINFO, null);
0088 }
0089 try {
0090 for (Type type : Type.values()) {
0091 Object[] rowData = new Object[] {
0092 type.getName(),
0093 type.toJavaSQLType(),
0094 type.getMaxPrecision(),
0095 type.getLiteralPrefix(),
0096 type.getLiteralSuffix(),
0097 type.getCreateParams(),
0098 type.getNullable(),
0099 type.isCaseSensitive(),
0100 type.getSearchable(),
0101 type.isUnsignedAttribute(),
0102 type.isFixedPrecScale(),
0103 type.isAutoIncrement(),
0104 type.getLocalizedName(),
0105 type.getMinimumScale(),
0106 type.getMaximumScale(),
0107 null,
0108 null,
0109 type.getNumPrecRadix()
0110 };
0111 rowSet.addRow(rowData);
0112 }
0113 setState(OperationState.FINISHED);
0114 } catch (Exception e) {
0115 setState(OperationState.ERROR);
0116 throw new HiveSQLException(e);
0117 }
0118 }
0119
0120
0121
0122
0123
0124 @Override
0125 public TableSchema getResultSetSchema() throws HiveSQLException {
0126 assertState(OperationState.FINISHED);
0127 return RESULT_SET_SCHEMA;
0128 }
0129
0130
0131
0132
0133 @Override
0134 public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
0135 assertState(OperationState.FINISHED);
0136 validateDefaultFetchOrientation(orientation);
0137 if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
0138 rowSet.setStartOffset(0);
0139 }
0140 return rowSet.extractSubset((int)maxRows);
0141 }
0142 }