Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CollectionStructType.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.analysis;
16 
17 import java.util.ArrayList;
18 
19 import jline.internal.Preconditions;
20 
27 import com.google.common.collect.Lists;
28 
37 public class CollectionStructType extends StructType {
38  // True if this struct describes the fields of a map,
39  // false if it describes the fields of an array.
40  private final boolean isMapStruct_;
41 
42  // Field that can be skipped by implicit paths if its type is a struct.
43  private final StructField optionalField_;
44 
45  private CollectionStructType(ArrayList<StructField> fields, boolean isMapStruct) {
46  super(fields);
48  if (isMapStruct_) {
50  } else {
52  }
53  Preconditions.checkNotNull(optionalField_);
54  }
55 
57  Type itemType = arrayType.getItemType();
58  ArrayList<StructField> fields = Lists.newArrayListWithCapacity(2);
59  // The item field name comes before the pos field name so that a path to the
60  // stored item corresponds to its physical path.
61  fields.add(new StructField(Path.ARRAY_ITEM_FIELD_NAME, itemType));
63  return new CollectionStructType(fields, false);
64  }
65 
67  ArrayList<StructField> mapFields = Lists.newArrayListWithCapacity(2);
68  mapFields.add(new StructField(Path.MAP_KEY_FIELD_NAME, mapType.getKeyType()));
69  mapFields.add(new StructField(Path.MAP_VALUE_FIELD_NAME, mapType.getValueType()));
70  return new CollectionStructType(mapFields, true);
71  }
72 
74  public boolean isMapStruct() { return isMapStruct_; }
75  public boolean isArrayStruct() { return !isMapStruct_; }
76 }
static final ScalarType BIGINT
Definition: Type.java:50
static CollectionStructType createMapStructType(MapType mapType)
CollectionStructType(ArrayList< StructField > fields, boolean isMapStruct)
static final String MAP_VALUE_FIELD_NAME
Definition: Path.java:79
StructField getField(String fieldName)
Definition: StructType.java:52
static final String ARRAY_POS_FIELD_NAME
Definition: Path.java:77
static final String ARRAY_ITEM_FIELD_NAME
Definition: Path.java:76
static CollectionStructType createArrayStructType(ArrayType arrayType)
static final String MAP_KEY_FIELD_NAME
Definition: Path.java:78