Examples of TupleSchema


Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

    public void dumpSchema(String alias) throws IOException{
    LogicalPlan lp = aliases.get(alias);
    if (lp == null)
        throw new IOException("Invalid alias - " + alias);

    TupleSchema schema = lp.getOpTable().get(lp.getRoot()).outputSchema();

    System.out.println(schema.toString());   
    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

    /**
     * @param input Schema of the input
     * @return Schema of the output
     */
    public Schema outputSchema(Schema input) {
        return new TupleSchema();
    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

        }
    }

    @Override
    public Schema outputSchema(Schema input) {
        TupleSchema schema = new TupleSchema();
        schema.add(new AtomSchema("token"));
        return schema;
    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

        DataBag newInputData = newBaseData.get(op);
        if(newInputData == null) {
          newInputData = BagFactory.getInstance().newDefaultBag();
          newBaseData.put(op, newInputData);
        }
        TupleSchema schema = op.outputSchema();
       
        // first of all, we are required to guarantee that there is at least one output tuple
        if (outputConstraints.cardinality() == 0 && inputData.cardinality() == 0) {
            outputConstraints.add(new Tuple(schema.numFields()));   // add an output constraint for one tuple
        }
       
        // create example tuple to steal values from when we encounter "don't care" fields (i.e. null fields)
        Tuple exampleTuple;
        if (inputData.cardinality() > 0) {
            // select first tuple from input data
            exampleTuple = inputData.iterator().next();
        } else {
            // input data is empty, so make up a tuple
            Tuple exampleT = new Tuple(schema.numFields());
            exampleTuple = new ExampleTuple();
            exampleTuple.copyFrom(exampleT);
            for (int i = 0; i < exampleTuple.arity(); i++) exampleTuple.setField(i, "0");
        }
       
        // run through output constraints; for each one synthesize a tuple and add it to the base data
        // (while synthesizing individual fields, try to match fields that exist in the real data)
        for (Iterator<Tuple> it = outputConstraints.iterator(); it.hasNext(); ) {
            Tuple outputConstraint = it.next();
           
            // sanity check:
            if (outputConstraint.arity() != schema.numFields()) throw new RuntimeException("Internal error: incorrect number of fields in constraint tuple.");
           
            Tuple inputT = new Tuple(outputConstraint.arity());
            ExampleTuple inputTuple = new ExampleTuple();
            inputTuple.copyFrom(inputT);
            for (int i = 0; i < inputTuple.arity(); i++) {
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

        }
    }
   
    static void AugmentBaseData(LOEval op, Map<LOLoad, DataBag> baseData, Map<LOLoad, DataBag> newBaseData, Map<LogicalOperator, DataBag> derivedData, DataBag outputConstraints, PigContext pigContext) throws IOException {
        LogicalOperator inputOp = op.getOpTable().get(op.getInputs().get(0));
        TupleSchema inputSchema = inputOp.outputSchema();
        DataBag inputConstraints = BagFactory.getInstance().newDefaultBag();
        DataBag outputData = derivedData.get(op);
        DataBag inputData = derivedData.get(inputOp);

        EvalSpec spec = op.getSpec();
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

    }

    @Override
    public TupleSchema outputSchema() {
        if (schema == null) {
            TupleSchema longest = opTable.get(getInputs().get(0)).outputSchema();
            int current = 0;
          for (OperatorKey opKey: getInputs()) {
              LogicalOperator lo = opTable.get(opKey);
             
              if (lo != null && lo.outputSchema() != null &&
                  lo.outputSchema().numFields() > current) {
                  longest = lo.outputSchema();
                  current = longest.numFields();
                }
            }
            schema = longest.copy();
        }

        schema.setAlias(alias);
        return schema;
    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

            String a = schema.getAlias();
            if (a == null) mStream.print("$" + pos);
            else mStream.print(a);
        } else if (schema instanceof TupleSchema) {
            mStream.print("(");
            TupleSchema ts = (TupleSchema)schema;
            int sz = ts.numFields();
            for (int j = 0; j < sz; j++) {
                if (j != 0) mStream.print(", ");
                Schema s = ts.schemaFor(j);
                if (s == null) mStream.print("$" + j);
                else printSchema(s, j);
            }
            mStream.print(")");
        } else {
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

        return new ArrayList<String>();
    }

    @Override
    protected Schema mapInputSchema(Schema schema) {
        return new TupleSchema();
    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

        assertTrue(output.strval().equals(expected));

        // test schema creation
        String fieldName = "field1";
        AtomSchema fieldSchema = new AtomSchema(fieldName);
        TupleSchema tupleSchema = new TupleSchema();
        tupleSchema.add(fieldSchema, false);
        Schema outSchema = func.outputSchema(tupleSchema);
        assertTrue(outSchema.toString().equals("upper_" + fieldName));

    }
View Full Code Here

Examples of org.apache.pig.impl.logicalLayer.schema.TupleSchema

    }

    @Override
    public TupleSchema outputSchema() {
        if (schema == null) {
            schema = new TupleSchema();


            Schema groupElementSchema =
                specs.get(0).getOutputSchemaForPipe(opTable.get(getInputs().get(0)).
                                                    outputSchema());
            if (groupElementSchema == null) {
                groupElementSchema = new TupleSchema();
                groupElementSchema.setAlias("group");
            } else {

                if (!(groupElementSchema instanceof TupleSchema))
                    throw new RuntimeException
                        ("Internal Error: Schema of group expression was atomic");
                List<Schema> fields =
                    ((TupleSchema) groupElementSchema).getFields();

                if (fields.size() < 2)
                    throw new RuntimeException
                        ("Internal Error: Schema of group expression retured <2 fields");

                if (fields.size() == 2) {
                    groupElementSchema = fields.get(0);
                    groupElementSchema.removeAllAliases();
                    groupElementSchema.setAlias("group");
                } else {
                    groupElementSchema = new TupleSchema();
                    groupElementSchema.setAlias("group");

                    for (int i = 0; i < fields.size() - 1; i++) {
                        ((TupleSchema) groupElementSchema).add(fields.get(i));
                    }
                }

            }

            schema.add(groupElementSchema);

          for (OperatorKey key: getInputs()) {
              LogicalOperator lo = opTable.get(key);
                TupleSchema inputSchema = lo.outputSchema();
                if (inputSchema == null)
                    inputSchema = new TupleSchema();
                schema.add(inputSchema);
            }
        }

        schema.setAlias(alias);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.