((ArraySegmentContext)_localctx).seg = new ArraySegment((((ArraySegmentContext)_localctx).Number!=null?((ArraySegmentContext)_localctx).Number.getText():null)); } else { ((ArraySegmentContext)_localctx).seg = new ArraySegment((((ArraySegmentContext)_localctx).Number!=null?((ArraySegmentContext)_localctx).Number.getText():null), (((ArraySegmentContext)_localctx).s1 == null ? ((ArraySegmentContext)_localctx).s2.seg : ((ArraySegmentContext)_localctx).s1.seg));
/** * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}. * * @param schemaPath {@link SchemaPath} instance that should be converted * @return {@link FieldPath} equivalent of the specified {@link SchemaPath}. */ public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) { Deque<PathSegment> pathSegments = Queues.newArrayDeque(); PathSegment pathSegment = schemaPath.getRootSegment(); while (pathSegment != null) { pathSegments.push(pathSegment); pathSegment = pathSegment.getChild(); } FieldSegment child = null; while (!pathSegments.isEmpty()) { pathSegment = pathSegments.pop(); if (pathSegment.isNamed()) { child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child, false); } else { child = new FieldSegment.IndexSegment(String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child); } } return new FieldPath((FieldSegment.NameSegment) child); } }
private static NamePart getNamePart(PathSegment s) { if (s == null) { return null; } NamePart.Builder b = NamePart.newBuilder(); if (s.getChild() != null) { NamePart namePart = getNamePart(s.getChild()); if (namePart != null) { b.setChild(namePart); } } if (s.isArray()) { if (s.getArraySegment().hasIndex()) { throw new IllegalStateException("You cannot convert a indexed schema path to a NamePart. NameParts can only reference Vectors, not individual records or values."); } b.setType(Type.ARRAY); } else { b.setType(Type.NAME); b.setName(s.getNameSegment().getPath()); } return b.build(); }
((ArraySegmentContext)_localctx).seg = new ArraySegment((((ArraySegmentContext)_localctx).Number!=null?((ArraySegmentContext)_localctx).Number.getText():null)); } else { ((ArraySegmentContext)_localctx).seg = new ArraySegment((((ArraySegmentContext)_localctx).Number!=null?((ArraySegmentContext)_localctx).Number.getText():null), (((ArraySegmentContext)_localctx).s1 == null ? ((ArraySegmentContext)_localctx).s2.seg : ((ArraySegmentContext)_localctx).s1.seg));
Preconditions.checkArgument(path.getRootSegment().getChild().isArray(), String.format("Selected column '%s' must be an array index", pathStr)); int index = path.getRootSegment().getChild().getArraySegment().getIndex(); columnIds.add(index);
int index = path.getRootSegment().getChild().getArraySegment().getIndex(); columnIds.add(index);
/** * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}. * * @param schemaPath {@link SchemaPath} instance that should be converted * @return {@link FieldPath} equivalent of the specified {@link SchemaPath}. */ public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) { Deque<PathSegment> pathSegments = Queues.newArrayDeque(); PathSegment pathSegment = schemaPath.getRootSegment(); while (pathSegment != null) { pathSegments.push(pathSegment); pathSegment = pathSegment.getChild(); } FieldSegment child = null; while (!pathSegments.isEmpty()) { pathSegment = pathSegments.pop(); if (pathSegment.isNamed()) { child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child, false); } else { child = new FieldSegment.IndexSegment(String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child); } } return new FieldPath((FieldSegment.NameSegment) child); } }
@Override public Void visitSchemaPath(SchemaPath path, StringBuilder sb) throws RuntimeException { PathSegment seg = path.getRootSegment(); if (seg.isArray()) { throw new IllegalStateException("Drill doesn't currently support top level arrays"); } sb.append('`'); sb.append(escapeBackTick(seg.getNameSegment().getPath())); sb.append('`'); while ( (seg = seg.getChild()) != null) { if (seg.isNamed()) { sb.append('.'); sb.append('`'); sb.append(escapeBackTick(seg.getNameSegment().getPath())); sb.append('`'); } else { sb.append('['); sb.append(seg.getArraySegment().getIndex()); sb.append(']'); } } return null; }
private void parseArray(NameSegment arraySeg) { String name = arraySeg.getPath(); int index = ((ArraySegment) arraySeg.getChild()).getIndex(); RequestedColumnImpl member = getImpl(name); if (member == null) { member = new RequestedColumnImpl(this, name); projection.add(name, member); } else if (member.isSimple()) { // Saw both a and a[x]. Occurs in project list. // Project all elements. member.projectAllElements(); return; } else if (member.hasIndex(index)) { throw UserException .validationError() .message("Duplicate array index in project list: %s[%d]", member.fullName(), index) .build(logger); } member.addIndex(index); }
private static NamePart getNamePart(PathSegment s) { if (s == null) { return null; } NamePart.Builder b = NamePart.newBuilder(); if (s.getChild() != null) { NamePart namePart = getNamePart(s.getChild()); if (namePart != null) { b.setChild(namePart); } } if (s.isArray()) { if (s.getArraySegment().hasIndex()) { throw new IllegalStateException("You cannot convert a indexed schema path to a NamePart. NameParts can only reference Vectors, not individual records or values."); } b.setType(Type.ARRAY); } else { b.setType(Type.NAME); b.setName(s.getNameSegment().getPath()); } return b.build(); }
/** * Returns {@link SchemaPath} equivalent of the specified {@link FieldPath}. */ public static SchemaPath fieldPath2SchemaPath(FieldPath fieldPath) { Stack<FieldSegment> fieldSegments = new Stack<FieldSegment>(); FieldSegment seg = fieldPath.getRootSegment(); while (seg != null) { fieldSegments.push(seg); seg = seg.getChild(); } PathSegment child = null; while (!fieldSegments.isEmpty()) { seg = fieldSegments.pop(); if (seg.isNamed()) { child = new PathSegment.NameSegment(((FieldSegment.NameSegment)seg).getName(), child); } else { child = new PathSegment.ArraySegment(((FieldSegment.IndexSegment)seg).getIndex(), child); } } return new SchemaPath((PathSegment.NameSegment)child); }
/** * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}. */ public static FieldPath schemaPath2FieldPath(SchemaPath column) { Stack<PathSegment> pathSegments = new Stack<PathSegment>(); PathSegment seg = column.getRootSegment(); while (seg != null) { pathSegments.push(seg); seg = seg.getChild(); } FieldSegment child = null; while (!pathSegments.isEmpty()) { seg = pathSegments.pop(); if (seg.isNamed()) { child = new FieldSegment.NameSegment(((PathSegment.NameSegment)seg).getPath(), child, false); } else { child = new FieldSegment.IndexSegment(((PathSegment.ArraySegment)seg).getIndex(), child); } } return new FieldPath((FieldSegment.NameSegment) child); }
/** * Converts literal into path segment based on its type. * For unsupported types, returns null. * * @param literal literal * @return new path segment, null otherwise */ public static PathSegment convertLiteral(RexLiteral literal) { switch (literal.getType().getSqlTypeName()) { case CHAR: return new PathSegment.NameSegment(RexLiteral.stringValue(literal)); case INTEGER: return new PathSegment.ArraySegment(RexLiteral.intValue(literal)); default: return null; } } }
public SchemaPath getChild(int index) { NameSegment newRoot = rootSegment.cloneWithNewChild(new ArraySegment(index)); return new SchemaPath(newRoot); }
@Override public String toString() { return "ArraySegment [index=" + index + ", getChild()=" + getChild() + "]"; }
@Override public boolean segmentEquals(PathSegment obj) { if (this == obj) { return true; } else if (obj == null) { return false; } else if (obj instanceof ArraySegment) { return index == ((ArraySegment)obj).getIndex(); } return false; }
private static PathSegment convertLiteral(RexLiteral literal) { switch (literal.getType().getSqlTypeName()) { case CHAR: return new PathSegment.NameSegment(RexLiteral.stringValue(literal)); case INTEGER: return new PathSegment.ArraySegment(RexLiteral.intValue(literal)); default: return null; } }
private static PathSegment getPathSegment(NamePart n) { PathSegment child = n.hasChild() ? getPathSegment(n.getChild()) : null; if (n.getType() == Type.ARRAY) { return new ArraySegment(child); } else { return new NameSegment(n.getName(), child); } }
@Override public PathSegment clone() { PathSegment seg = index < 0 ? new ArraySegment((PathSegment) null) : new ArraySegment(index); if (getChild() != null) { seg.setChild(getChild().clone()); } return seg; }