use of edu.iu.dsc.tws.data.api.splits.CSVInputSplit in project twister2 by DSC-SPIDAL.
the class CSVInputPartitioner method createInputSplits.
@Override
public FileInputSplit<OT>[] createInputSplits(int minNumSplits) throws IOException {
// take the desired number of splits into account
int curminNumSplits = Math.max(minNumSplits, this.numSplits);
final Path path = this.filePath;
final List<FileInputSplit> inputSplits = new ArrayList<>(curminNumSplits);
// get all the files that are involved in the splits
List<FileStatus> files = new ArrayList<>();
final FileSystem fs = FileSystemUtils.get(path, config);
final FileStatus pathFile = fs.getFileStatus(path);
long totalLength = 0;
if (pathFile.isDir()) {
totalLength += sumFilesInDir(path, files, true);
} else {
files.add(pathFile);
totalLength += pathFile.getLen();
}
if (files.size() > 1) {
throw new IllegalStateException("FixedInputPartitioner does not support multiple files" + "currently");
}
for (final FileStatus file : files) {
final long lineCount = dataSize;
int splSize = (int) (lineCount / curminNumSplits);
final long len = file.getLen();
long[] splitSizes = getSplitSizes(fs, file.getPath(), curminNumSplits, splSize);
int position = 0;
if (len > 0) {
for (int i = 0; i < splitSizes.length; i++) {
String[] hosts = new String[0];
final FileInputSplit fis = new CSVInputSplit(i, file.getPath(), position, splitSizes[i], hosts);
position += splitSizes[i];
inputSplits.add(fis);
}
} else {
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, 0);
String[] hosts;
if (blocks.length > 0) {
hosts = blocks[0].getHosts();
} else {
hosts = new String[0];
}
final FileInputSplit fis = new CSVInputSplit(0, file.getPath(), 0, 0, hosts);
inputSplits.add(fis);
}
}
return inputSplits.toArray(new FileInputSplit[inputSplits.size()]);
}
use of edu.iu.dsc.tws.data.api.splits.CSVInputSplit in project twister2 by DSC-SPIDAL.
the class CompleteCSVInputPartitioner method createInputSplits.
/**
* It creates the split for the complete file.
*
* @param minNumSplits Number of minimal input splits, as a hint.
*/
@Override
public FileInputSplit<OT>[] createInputSplits(int minNumSplits) throws IOException {
if (minNumSplits < 1) {
throw new IllegalArgumentException("Number of input splits has to be at least 1.");
}
int curminNumSplits = Math.max(minNumSplits, this.numSplits);
final Path path = this.filePath;
final List<FileInputSplit> inputSplits = new ArrayList<>(curminNumSplits);
List<FileStatus> files = new ArrayList<>();
long totalLength = 0;
final FileSystem fs = FileSystemUtils.get(path, config);
final FileStatus pathFile = fs.getFileStatus(path);
if (pathFile.isDir()) {
totalLength += sumFilesInDir(path, files, true);
} else {
files.add(pathFile);
totalLength += pathFile.getLen();
}
final long maxSplitSize = totalLength;
// Generate the splits
int splitNum = 0;
for (final FileStatus file : files) {
final long len = file.getLen();
final long blockSize = file.getBlockSize();
final long localminSplitSize;
if (this.minSplitSize <= blockSize) {
localminSplitSize = this.minSplitSize;
} else {
LOG.log(Level.WARNING, "Minimal split size of " + this.minSplitSize + " is larger than the block size of " + blockSize + ". Decreasing minimal split size to block size.");
localminSplitSize = blockSize;
}
final long splitSize = Math.max(localminSplitSize, Math.min(maxSplitSize, blockSize));
if (len > 0) {
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, len);
Arrays.sort(blocks);
long position = 0;
int blockIndex = 0;
for (int i = 0; i < curminNumSplits; i++) {
blockIndex = getBlockIndexForPosition(blocks, position, splitSize, blockIndex);
final FileInputSplit fis = new CSVInputSplit(splitNum++, file.getPath(), position, splitSize, blocks[blockIndex].getHosts());
inputSplits.add(fis);
}
} else {
// special case with a file of zero bytes size
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, 0);
String[] hosts;
if (blocks.length > 0) {
hosts = blocks[0].getHosts();
} else {
hosts = new String[0];
}
for (int i = 0; i < curminNumSplits; i++) {
final FileInputSplit fis = new CSVInputSplit(splitNum++, file.getPath(), 0, 0, hosts);
inputSplits.add(fis);
}
}
}
return inputSplits.toArray(new FileInputSplit[inputSplits.size()]);
}
use of edu.iu.dsc.tws.data.api.splits.CSVInputSplit in project twister2 by DSC-SPIDAL.
the class CompleteArrowInputPartitioner method createInputSplits.
/**
* It creates the split for the complete file.
*
* @param minNumSplits Number of minimal input splits, as a hint.
*/
@Override
public FileInputSplit<OT>[] createInputSplits(int minNumSplits) throws IOException {
if (minNumSplits < 1) {
throw new IllegalArgumentException("Number of input splits has to be at least 1.");
}
int curminNumSplits = Math.max(minNumSplits, this.numSplits);
final Path path = this.filePath;
final List<FileInputSplit> inputSplits = new ArrayList<>(curminNumSplits);
List<FileStatus> files = new ArrayList<>();
long totalLength = 0;
final FileSystem fs = FileSystemUtils.get(path, config);
final FileStatus pathFile = fs.getFileStatus(path);
if (pathFile.isDir()) {
totalLength += sumFilesInDir(path, files, true);
} else {
files.add(pathFile);
totalLength += pathFile.getLen();
}
final long maxSplitSize = totalLength;
// Generate the splits
int splitNum = 0;
for (final FileStatus file : files) {
final long len = file.getLen();
final long blockSize = file.getBlockSize();
final long localminSplitSize;
if (this.minSplitSize <= blockSize) {
localminSplitSize = this.minSplitSize;
} else {
LOG.log(Level.WARNING, "Minimal split size of " + this.minSplitSize + " is larger than the block size of " + blockSize + ". Decreasing minimal split size to block size.");
localminSplitSize = blockSize;
}
final long splitSize = Math.max(localminSplitSize, Math.min(maxSplitSize, blockSize));
if (len > 0) {
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, len);
Arrays.sort(blocks);
long position = 0;
int blockIndex = 0;
for (int i = 0; i < curminNumSplits; i++) {
blockIndex = getBlockIndexForPosition(blocks, position, splitSize, blockIndex);
final FileInputSplit fis = new CSVInputSplit(splitNum++, file.getPath(), position, splitSize, blocks[blockIndex].getHosts());
inputSplits.add(fis);
}
} else {
// special case with a file of zero bytes size
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, 0);
String[] hosts;
if (blocks.length > 0) {
hosts = blocks[0].getHosts();
} else {
hosts = new String[0];
}
for (int i = 0; i < curminNumSplits; i++) {
final FileInputSplit fis = new CSVInputSplit(splitNum++, file.getPath(), 0, 0, hosts);
inputSplits.add(fis);
}
}
}
return inputSplits.toArray(new FileInputSplit[inputSplits.size()]);
}
Aggregations