Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StructField.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.catalog;
16 
17 import com.cloudera.impala.thrift.TColumnType;
18 import com.cloudera.impala.thrift.TStructField;
19 import com.cloudera.impala.thrift.TTypeNode;
20 
25 public class StructField {
26  protected final String name_;
27  protected final Type type_;
28  protected final String comment_;
29  protected int position_; // in struct
30 
31  public StructField(String name, Type type, String comment) {
32  name_ = name;
33  type_ = type;
34  comment_ = comment;
35  }
36 
37  public StructField(String name, Type type) {
38  this(name, type, null);
39  }
40 
41  public String getComment() { return comment_; }
42  public String getName() { return name_; }
43  public Type getType() { return type_; }
44  public int getPosition() { return position_; }
45  public void setPosition(int position) { position_ = position; }
46 
47  public String toSql() {
48  StringBuilder sb = new StringBuilder(name_);
49  if (type_ != null) sb.append(":" + type_.toSql());
50  if (comment_ != null) sb.append(String.format(" COMMENT '%s'", comment_));
51  return sb.toString();
52  }
53 
54  public void toThrift(TColumnType container, TTypeNode node) {
55  TStructField field = new TStructField();
56  field.setName(name_);
57  if (comment_ != null) field.setComment(comment_);
58  node.struct_fields.add(field);
59  type_.toThrift(container);
60  }
61 
62  @Override
63  public boolean equals(Object other) {
64  if (!(other instanceof StructField)) return false;
65  StructField otherStructField = (StructField) other;
66  return otherStructField.name_.equals(name_) && otherStructField.type_.equals(type_);
67  }
68 }
void toThrift(TColumnType container, TTypeNode node)
StructField(String name, Type type)
StructField(String name, Type type, String comment)
string name
Definition: cpu-info.cc:50