Package org.apache.pig

Examples of org.apache.pig.LoadFunc$RequiredField


                // Instantiate both LoadFunc objects to compare them for
                // equality
                StoreFunc streamStorer =
                    (StoreFunc)PigContext.instantiateFuncFromSpec(
                            streamInputSpec.getSpec());
                LoadFunc inputLoader = (LoadFunc)PigContext.instantiateFuncFromSpec(
                                             loadFileSpec.getFuncSpec());
                LogFactory.getLog(this.getClass()).info("streamStorer:" + streamStorer + "," +
                        "inputLoader:" + inputLoader);
                // Check if the streaming command's inputSpec also implements
                // LoadFunc and if it does, are they of the same _reversible_
View Full Code Here


            HandleSpec streamOutputSpec = command.getOutputSpec();
           
            FileSpec storeFileSpec = store.getOutputFile();
           
            // Instantiate both to compare them for equality
            LoadFunc streamLoader =
                (LoadFunc)PigContext.instantiateFuncFromSpec(
                        streamOutputSpec.getSpec());
           
            StoreFunc outputStorer = (StoreFunc)PigContext.instantiateFuncFromSpec(
                                         storeFileSpec.getFuncSpec());
           
            // Check if the streaming command's outputSpec also implements
            // StoreFunc and if it does, are they of the same _reversible_
            // type?
            boolean sameType = false;
            try {
                // Check if the streamLoader is _reversible_ as
                // the inputLoader ...
                if (streamLoader instanceof StoreFunc) {
                    // Cast to check if they are of the same type...
                    streamLoader.getClass().cast(outputStorer);
                   
                    // Now check if they both are reversible...
                    if (streamLoader instanceof ReversibleLoadStoreFunc &&
                        outputStorer instanceof ReversibleLoadStoreFunc) {
                        sameType = true;
                    }
                }
            } catch (ClassCastException cce) {
                sameType = false;
            }
            // Check if both LoadFunc objects belong to the same type and
            // are equivalent
            if (sameType && streamLoader.equals(outputStorer)) {
                // Since they both are the same, we can flip them
                // for BinaryStorage
                mOptimizeStore = true;                   
            }
        }
View Full Code Here

    @Test
    public void testLFPig() throws Exception {
        String input1 = "this:is:delimited:by:a:colon\n";
        int arity1 = 6;

        LoadFunc p1 = new PigStorage(":");
        FakeFSInputStream ffis1 = new FakeFSInputStream(input1.getBytes());
        p1.bindTo(null, new BufferedPositionedInputStream(ffis1), 0, input1.getBytes().length);
        Tuple f1 = p1.getNext();
        assertTrue(f1.size() == arity1);

        LoadFunc p15 = new PigStorage();
        StringBuilder sb = new StringBuilder();
        int LOOP_COUNT = 100;
        for (int i = 0; i < LOOP_COUNT; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                sb.append(i + "\t" + i + "\t" + j % 2 + "\n");
            }
        }
        byte bytes[] = sb.toString().getBytes();
        FakeFSInputStream ffis15 = new FakeFSInputStream(bytes);
        p15.bindTo(null, new BufferedPositionedInputStream(ffis15), 0, bytes.length);
        int count = 0;
        while (true) {
            Tuple f15 = p15.getNext();
            if (f15 == null)
                break;
            count++;
            assertEquals(3, f15.size());
        }
        assertEquals(LOOP_COUNT * LOOP_COUNT, count);

        String input2 = ":this:has:a:leading:colon\n";
        int arity2 = 6;

        LoadFunc p2 = new PigStorage(":");
        FakeFSInputStream ffis2 = new FakeFSInputStream(input2.getBytes());
        p2.bindTo(null, new BufferedPositionedInputStream(ffis2), 0, input2.getBytes().length);
        Tuple f2 = p2.getNext();
        assertTrue(f2.size() == arity2);

        String input3 = "this:has:a:trailing:colon:\n";
        int arity3 = 6;

        LoadFunc p3 = new PigStorage(":");
        FakeFSInputStream ffis3 = new FakeFSInputStream(input3.getBytes());
        p3.bindTo(null, new BufferedPositionedInputStream(ffis3), 0, input1.getBytes().length);
        Tuple f3 = p3.getNext();
        assertTrue(f3.size() == arity3);
    }
View Full Code Here

    public void testLFText() throws Exception {
        String input1 = "This is some text.\nWith a newline in it.\n";
        String expected1 = "This is some text.";
        String expected2 = "With a newline in it.";
        FakeFSInputStream ffis1 = new FakeFSInputStream(input1.getBytes());
        LoadFunc text1 = new TextLoader();
        text1.bindTo(null, new BufferedPositionedInputStream(ffis1), 0, input1.getBytes().length);
        Tuple f1 = text1.getNext();
        Tuple f2 = text1.getNext();
        assertTrue(expected1.equals(f1.get(0).toString()) &&
            expected2.equals(f2.get(0).toString()));

        String input2 = "";
        FakeFSInputStream ffis2 = new FakeFSInputStream(input2.getBytes());
        LoadFunc text2 = new TextLoader();
        text2.bindTo(null, new BufferedPositionedInputStream(ffis2), 0, input2.getBytes().length);
        Tuple f3 = text2.getNext();
        assertTrue(f3 == null);
    }
View Full Code Here

        sfunc.putNext(f1);
        sfunc.finish();
       
        FakeFSInputStream is = new FakeFSInputStream(buf);
        LoadFunc lfunc = new PigStorage();
        lfunc.bindTo(null, new BufferedPositionedInputStream(is), 0, buf.length);
        Tuple f2 = lfunc.getNext();
       
        assertTrue(f1.equals(f2));       
    }
View Full Code Here

      t.append(r.nextInt());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
View Full Code Here

      t.append(r.nextLong());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
View Full Code Here

      t.append(r.nextFloat());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
View Full Code Here

      t.append(r.nextDouble());
      bag.add(t);
    }
   
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
View Full Code Here

  }
 
  @Test
  public void testStringToOther() throws PlanException, ExecException {
    POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
    LoadFunc load = new TestLoader();
    op.setLoadFSpec(new FuncSpec(load.getClass().getName()));
    POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
    PhysicalPlan plan = new PhysicalPlan();
    plan.add(prj);
    plan.add(op);
    plan.connect(prj, op);
View Full Code Here

TOP

Related Classes of org.apache.pig.LoadFunc$RequiredField

Copyright © 2018 www.massapicom. 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.