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;
0020
0021 import org.apache.hadoop.hive.serde2.thrift.Type;
0022 import org.apache.hive.service.rpc.thrift.TColumnDesc;
0023
0024
0025
0026
0027
0028
0029 public class ColumnDescriptor {
0030 private final String name;
0031 private final String comment;
0032 private final TypeDescriptor type;
0033
0034 private final int position;
0035
0036 public ColumnDescriptor(String name, String comment, TypeDescriptor type, int position) {
0037 this.name = name;
0038 this.comment = comment;
0039 this.type = type;
0040 this.position = position;
0041 }
0042
0043 public ColumnDescriptor(TColumnDesc tColumnDesc) {
0044 name = tColumnDesc.getColumnName();
0045 comment = tColumnDesc.getComment();
0046 type = new TypeDescriptor(tColumnDesc.getTypeDesc());
0047 position = tColumnDesc.getPosition();
0048 }
0049
0050 public static ColumnDescriptor newPrimitiveColumnDescriptor(String name, String comment, Type type, int position) {
0051
0052
0053 return new ColumnDescriptor(name, comment, new TypeDescriptor(type), position);
0054 }
0055
0056 public String getName() {
0057 return name;
0058 }
0059
0060 public String getComment() {
0061 return comment;
0062 }
0063
0064 public TypeDescriptor getTypeDescriptor() {
0065 return type;
0066 }
0067
0068 public int getOrdinalPosition() {
0069 return position;
0070 }
0071
0072 public TColumnDesc toTColumnDesc() {
0073 TColumnDesc tColumnDesc = new TColumnDesc();
0074 tColumnDesc.setColumnName(name);
0075 tColumnDesc.setComment(comment);
0076 tColumnDesc.setTypeDesc(type.toTTypeDesc());
0077 tColumnDesc.setPosition(position);
0078 return tColumnDesc;
0079 }
0080
0081 public Type getType() {
0082 return type.getType();
0083 }
0084
0085 public boolean isPrimitive() {
0086 return type.getType().isPrimitiveType();
0087 }
0088
0089 public String getTypeName() {
0090 return type.getTypeName();
0091 }
0092 }