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.metastore.api.FieldSchema;
0022 import org.apache.hive.service.cli.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 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     // Current usage looks like it's only for metadata columns, but if that changes then
0059     // this method may need to require a type qualifiers aruments.
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 }