2 * Copyright (c) 2007 Yahoo! Inc. All rights reserved.
3 * See accompanying LICENSE file.
5 package com
.yahoo
.pig
.impl
.mapreduceExec
;
7 import java
.io
.DataInput
;
8 import java
.io
.DataOutput
;
9 import java
.io
.IOException
;
11 import org
.apache
.hadoop
.fs
.FileSystem
;
12 import org
.apache
.hadoop
.fs
.Path
;
13 import org
.apache
.hadoop
.mapred
.InputSplit
;
15 import com
.yahoo
.pig
.StorageFunc
;
16 import com
.yahoo
.pig
.builtin
.PigStorage
;
17 import com
.yahoo
.pig
.impl
.PigContext
;
18 import com
.yahoo
.pig
.impl
.logicalLayer
.parser
.QueryParser
;
20 public class PigSplit
implements InputSplit
{
32 public PigSplit(FileSystem fs
, Path path
, String parser
, String groupFunc
, String mapFuncs
, int index
, long start
, long length
) {
37 this.groupFunc
= groupFunc
;
38 this.applyFunc
= mapFuncs
;
43 public String
getParser() {
47 public long getStart() {
51 public long getLength() {
54 public String
getGroupFunction() {
58 public String
getApplyFunction() {
62 public Path
getPath() {
66 public int getIndex() {
70 public StorageFunc
getLoadFunction() {
71 StorageFunc loader
= null;
72 if (this.parser
== null) {
73 loader
= new PigStorage();
76 loader
= (StorageFunc
) PigContext
.instantiateArgFunc(this.parser
);
77 }catch(Exception exp
) {
78 exp
.printStackTrace();
79 loader
= new PigStorage();
86 public String
[] getLocations() throws IOException
{
87 String hints
[][] = fs
.getFileCacheHints(file
, start
, length
);
89 for(int i
= 0; i
< hints
.length
; i
++) {
90 total
+= hints
[i
].length
;
92 String locations
[] = new String
[total
];
94 for(int i
= 0; i
< hints
.length
; i
++) {
95 for(int j
= 0; j
< hints
[i
].length
; j
++) {
96 locations
[count
++] = hints
[i
][j
];
102 public void readFields(DataInput is
) throws IOException
{
103 file
= new Path(is
.readUTF());
104 start
= is
.readLong();
105 length
= is
.readLong();
106 groupFunc
= is
.readUTF();
107 applyFunc
= is
.readUTF();
108 index
= is
.readInt();
109 parser
= is
.readUTF();
112 public void write(DataOutput os
) throws IOException
{
113 os
.writeUTF(file
.toString());
115 os
.writeLong(length
);
116 os
.writeUTF(groupFunc
);
117 os
.writeUTF(applyFunc
);