Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
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  * ColumnDescriptor.
0027  *
0028  */
0029 public class ColumnDescriptor {
0030   private final String name;
0031   private final String comment;
0032   private final TypeDescriptor type;
0033   // ordinal position of this column in the schema
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     // Current usage looks like it's only for metadata columns, but if that changes then
0052     // this method may need to require a type qualifiers aruments.
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 }