1 package com.cloudera.impala.catalog;
3 import java.util.ArrayList;
4 import java.util.HashMap;
6 import com.cloudera.impala.thrift.TColumnType;
7 import com.cloudera.impala.thrift.TStructField;
8 import com.cloudera.impala.thrift.TTypeNode;
9 import com.cloudera.impala.thrift.TTypeNodeType;
10 import com.google.common.base.Joiner;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Lists;
13 import com.google.common.collect.Maps;
19 private final HashMap<String, StructField>
fieldMap_ = Maps.newHashMap();
20 private final ArrayList<StructField>
fields_;
23 Preconditions.checkNotNull(fields);
25 for (
int i = 0; i < fields_.size(); ++i) {
26 fields_.get(i).setPosition(i);
27 fieldMap_.put(fields_.get(i).getName().toLowerCase(), fields_.get(i));
37 ArrayList<String> fieldsSql = Lists.newArrayList();
39 fieldsSql.add(f.toSql());
41 return String.format(
"STRUCT<%s>", Joiner.on(
",").join(fieldsSql));
45 field.setPosition(fields_.size());
47 fieldMap_.put(field.getName().toLowerCase(), field);
53 return fieldMap_.get(fieldName.toLowerCase());
62 public boolean equals(Object other) {
63 if (!(other instanceof
StructType))
return false;
64 StructType otherStructType = (
StructType) other;
70 TTypeNode node =
new TTypeNode();
71 container.types.add(node);
72 Preconditions.checkNotNull(
fields_);
73 Preconditions.checkNotNull(!fields_.isEmpty());
74 node.setType(TTypeNodeType.STRUCT);
75 node.setStruct_fields(
new ArrayList<TStructField>());
77 field.toThrift(container, node);
void addField(StructField field)
final ArrayList< StructField > fields_
void toThrift(TColumnType container)
final HashMap< String, StructField > fieldMap_
StructType(ArrayList< StructField > fields)
StructField getField(String fieldName)
boolean equals(Object other)
ArrayList< StructField > getFields()