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.metastore.api.FieldSchema;
0022 import org.apache.hive.service.cli.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 ColumnDescriptor(FieldSchema column, int position) {
0051 name = column.getName();
0052 comment = column.getComment();
0053 type = new TypeDescriptor(column.getType());
0054 this.position = position;
0055 }
0056
0057 public static ColumnDescriptor newPrimitiveColumnDescriptor(String name, String comment, Type type, int position) {
0058
0059
0060 return new ColumnDescriptor(name, comment, new TypeDescriptor(type), position);
0061 }
0062
0063 public String getName() {
0064 return name;
0065 }
0066
0067 public String getComment() {
0068 return comment;
0069 }
0070
0071 public TypeDescriptor getTypeDescriptor() {
0072 return type;
0073 }
0074
0075 public int getOrdinalPosition() {
0076 return position;
0077 }
0078
0079 public TColumnDesc toTColumnDesc() {
0080 TColumnDesc tColumnDesc = new TColumnDesc();
0081 tColumnDesc.setColumnName(name);
0082 tColumnDesc.setComment(comment);
0083 tColumnDesc.setTypeDesc(type.toTTypeDesc());
0084 tColumnDesc.setPosition(position);
0085 return tColumnDesc;
0086 }
0087
0088 public Type getType() {
0089 return type.getType();
0090 }
0091
0092 public boolean isPrimitive() {
0093 return type.getType().isPrimitiveType();
0094 }
0095
0096 public String getTypeName() {
0097 return type.getTypeName();
0098 }
0099 }