15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.List;
27 import com.google.common.base.Joiner;
28 import com.google.common.base.Preconditions;
29 import com.google.common.collect.Lists;
123 Preconditions.checkNotNull(rootDesc);
124 Preconditions.checkNotNull(rawPath);
135 Preconditions.checkNotNull(rootTable);
136 Preconditions.checkNotNull(rawPath);
146 public Path(
Path rootPath, List<String> relRawPath) {
147 Preconditions.checkNotNull(rootPath);
148 Preconditions.checkState(rootPath.isResolved());
149 Preconditions.checkNotNull(relRawPath);
153 rawPath_ = Lists.newArrayListWithCapacity(
154 rootPath.getRawPath().size() + relRawPath.size());
155 rawPath_.addAll(rootPath.getRawPath());
156 rawPath_.addAll(relRawPath);
157 matchedTypes_.addAll(rootPath.matchedTypes_);
158 matchedPositions_.addAll(rootPath.matchedPositions_);
172 Type currentType = null;
176 currentType = rootPath_.destType();
177 rawPathIdx = rootPath_.getRawPath().size();
179 currentType = rootDesc_.getType();
182 currentType = rootTable_.getType().getItemType();
186 while (rawPathIdx <
rawPath_.size()) {
187 if (!currentType.isComplexType())
return false;
190 StructField field = structType.getField(rawPath_.get(rawPathIdx));
194 field = ((CollectionStructType) structType).getOptionalField();
200 matchedTypes_.add(field.getType());
201 matchedPositions_.add(field.getPosition());
202 currentType = field.getType();
206 matchedTypes_.add(field.getType());
207 matchedPositions_.add(field.getPosition());
211 firstCollectionTypeIdx_ = matchedTypes_.size() - 1;
213 currentType = field.getType();
217 Preconditions.checkState(matchedTypes_.size() >=
rawPath_.size());
228 Preconditions.checkState(t.isComplexType());
231 return CollectionStructType.createArrayStructType((
ArrayType) t);
233 Preconditions.checkState(t.isMapType());
234 return CollectionStructType.createMapStructType((
MapType) t);
274 if (
rootDesc_ != null)
return rootDesc_.getType();
275 if (
rootTable_ != null)
return rootTable_.getType();
295 return rootTable_.getColumn(rawPath_.get(rawPath_.size() - 1));
310 List<String> result = Lists.newArrayListWithCapacity(rawPath_.size() + 2);
312 result.addAll(Lists.newArrayList(rootDesc_.getAlias().split(
"\\.")));
314 result.add(rootTable_.getDb().getName());
315 result.add(rootTable_.getName());
337 String pathRoot = null;
339 pathRoot = rootDesc_.getAlias();
341 pathRoot = rootTable_.getFullName();
343 if (
rawPath_.isEmpty())
return pathRoot;
344 return pathRoot +
"." + Joiner.on(
".").join(
rawPath_);
350 public static ArrayList<String>
createRawPath(String rootAlias, String fieldName) {
351 ArrayList<String> result = Lists.newArrayList(rootAlias.split(
"\\."));
352 result.add(fieldName);
357 Preconditions.checkState(rootPath.isResolved());
358 Path result =
new Path(rootPath, Lists.newArrayList(fieldNames));
final List< Type > matchedTypes_
int firstCollectionTypeIdx_
List< Integer > getMatchedPositions()
List< String > getFullyQualifiedRawPath()
Type getFirstCollectionType()
Path(Path rootPath, List< String > relRawPath)
final List< Integer > matchedPositions_
TupleDescriptor destTupleDesc()
String getFirstCollectionName()
static Path createRelPath(Path rootPath, String...fieldNames)
List< Integer > getAbsolutePath()
Path(Table rootTable, List< String > rawPath)
final List< String > rawPath_
Path(TupleDescriptor rootDesc, List< String > rawPath)
boolean hasNonDestCollection()
static ArrayList< String > createRawPath(String rootAlias, String fieldName)
static final String MAP_VALUE_FIELD_NAME
int firstCollectionPathIdx_
static final String ARRAY_POS_FIELD_NAME
List< Type > getMatchedTypes()
List< String > getRawPath()
static final String ARRAY_ITEM_FIELD_NAME
static StructType getTypeAsStruct(Type t)
TupleDescriptor getRootDesc()
static final String MAP_KEY_FIELD_NAME
List< Integer > absolutePath_
final TupleDescriptor rootDesc_