public static int[] getTargetIds(Schema inSchema, Schema outSchema) { int[] targetIds = new int[outSchema.size()]; int i = 0; for (Column target : outSchema.getRootColumns()) { targetIds[i] = inSchema.getColumnId(target.getQualifiedName()); i++; } return targetIds; }
public synchronized void addColumns(Schema schema) { for(Column column : schema.getRootColumns()) { addColumn(column); } }
/** * This method transforms the unqualified names of a schema to the qualified names. * * @param tableName a table name to be prefixed * @param schema a schema to be transformed * * @return */ public static SchemaProto getQualfiedSchema(String tableName, SchemaProto schema) { Schema restored = new Schema(schema); restored.setQualifier(tableName); return restored.getProto(); }
@Override public void init() throws IOException { if (targets == null) { targets = schema.toArray(); } prepareProjection(targets); super.init(); }
public void loadOutSchema() { Schema q2 = new Schema() .addColumn("s_acctbal", Type.FLOAT8) .addColumn("s_name", Type.TEXT) .addColumn("n_name", Type.TEXT) .addColumn("p_partkey", Type.INT4) .addColumn("p_mfgr", Type.TEXT) .addColumn("s_address", Type.TEXT) .addColumn("s_phone", Type.TEXT) .addColumn("s_comment", Type.TEXT); outSchemas.put("q2", q2); }
/** * Get a prefix of column partition path. For example, consider a column partition (col1, col2). * Then, you will get a string 'col1='. * * @param partitionColumn the schema of column partition * @return The first part string of column partition path. */ public static String getColumnPartitionPathPrefix(Schema partitionColumn) { StringBuilder sb = new StringBuilder(); sb.append(partitionColumn.getColumn(0).getSimpleName()).append("="); return sb.toString(); }
/** * Get common columns to be used as join keys of natural joins. */ public static Schema getNaturalJoinColumns(Schema left, Schema right) { Schema common = new Schema(); for (Column outer : left.getRootColumns()) { if (!common.containsByName(outer.getSimpleName()) && right.containsByName(outer.getSimpleName())) { common.addColumn(new Column(outer.getSimpleName(), outer.getDataType())); } } return common; }
public LazyTuple(Schema schema, byte[][] textBytes, long offset, byte[] nullBytes, SerializerDeserializer serde) { this.schema = schema; this.textBytes = textBytes; this.values = new Datum[schema.size()]; this.offset = offset; this.nullBytes = nullBytes; this.serializeDeserialize = serde; }
public static int[] getTargetIds(Schema inSchema, Schema outSchema) { int[] targetIds = new int[outSchema.size()]; int i = 0; for (Column target : outSchema.getColumns()) { targetIds[i] = inSchema.getColumnId(target.getQualifiedName()); i++; } return targetIds; }
public static List<ColumnStats> emptyColumnStats(Schema schema) { List<ColumnStats> stats = new ArrayList<>(schema.size()); for (Column column : schema.getRootColumns()) { stats.add(new ColumnStats(column)); } return stats; } }
private int[] getProjectionMap(Schema schema, Schema projection) { Column[] targets = projection.toArray(); int[] projectionMap = new int[targets.length]; for (int i = 0; i < targets.length; ++i) { int tid = schema.getColumnId(targets[i].getQualifiedName()); projectionMap[i] = tid; } return projectionMap; }
public void init() throws IOException { keySchema = PlannerUtil.sortSpecsToSchema(sortSpecs); keyProjector = new KeyProjector(inSchema, keySchema.toArray()); BSTIndex bst = new BSTIndex(context.getConf()); this.comp = new BaseTupleComparator(keySchema, sortSpecs); Path storeTablePath = new Path(context.getWorkDir(), "output"); LOG.info("Output data directory: " + storeTablePath); FileSystem fs = new RawLocalFileSystem(); fs.mkdirs(storeTablePath); this.appender = (FileAppender) ((FileTablespace) TablespaceManager.getDefault()) .getAppender(meta, outSchema, new Path(storeTablePath, "output")); this.appender.enableStats(keySchema.getAllColumns()); this.appender.init(); this.indexWriter = bst.getIndexWriter(new Path(storeTablePath, "index"), BSTIndex.TWO_LEVEL_INDEX, keySchema, comp, true); this.indexWriter.init(); super.init(); }
@Override public int compare(String o1, String o2) { return originlSchema.getColumnId(o1) - originlSchema.getColumnId(o2); } }
public Schema getProjectSchema() { Schema projected; // in the case where projected column or expression are given // the target can be an empty list. if (plan.hasTargets()) { projected = new Schema(); Set<Column> columnSet = new HashSet<Column>(); if (plan.hasQual()) { columnSet.addAll(EvalTreeUtil.findUniqueColumns(qual)); } for (Target t : plan.getTargets()) { columnSet.addAll(EvalTreeUtil.findUniqueColumns(t.getEvalTree())); } for (Column column : inSchema.getAllColumns()) { if (columnSet.contains(column)) { projected.addColumn(column); } } } else { // no any projected columns, meaning that all columns should be projected. // TODO - this implicit rule makes code readability bad. So, we should remove it later projected = outSchema; } return projected; }
/** * It allows a column visitor to traverse all columns in a schema in a depth-first order. * @param schema * @param function */ public static void visitSchema(Schema schema, ColumnVisitor function) { for(Column col : schema.getRootColumns()) { visitInDepthFirstOrder(0, NestedPathUtil.ROOT_PATH, function, col); } }