-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e92f4
commit 11ba58a
Showing
8 changed files
with
234 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/org/apache/sysds/runtime/compress/io/ReaderSparkCompressed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.apache.sysds.runtime.compress.io; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.mapred.SequenceFileInputFormat; | ||
import org.apache.spark.api.java.JavaPairRDD; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.sysds.runtime.compress.CompressedMatrixBlock; | ||
import org.apache.sysds.runtime.compress.colgroup.AColGroup; | ||
import org.apache.sysds.runtime.compress.colgroup.ADictBasedColGroup; | ||
import org.apache.sysds.runtime.compress.colgroup.dictionary.IDictionary; | ||
import org.apache.sysds.runtime.matrix.data.MatrixBlock; | ||
import org.apache.sysds.runtime.matrix.data.MatrixIndexes; | ||
|
||
import scala.Tuple2; | ||
|
||
public interface ReaderSparkCompressed { | ||
public static final Log LOG = LogFactory.getLog(ReaderSparkCompressed.class.getName()); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static JavaPairRDD<MatrixIndexes, MatrixBlock> getRDD(JavaSparkContext sc, String fileName) { | ||
JavaPairRDD<MatrixIndexes, CompressedWriteBlock> cmbrdd = sc.hadoopFile(fileName, SequenceFileInputFormat.class, | ||
MatrixIndexes.class, CompressedWriteBlock.class); | ||
JavaPairRDD<DictWritable.K, DictWritable> dictsRdd = sc.hadoopFile(fileName + ".dict", | ||
SequenceFileInputFormat.class, DictWritable.K.class, DictWritable.class); | ||
|
||
return combineRdds(cmbrdd, dictsRdd); | ||
} | ||
|
||
private static JavaPairRDD<MatrixIndexes, MatrixBlock> combineRdds( | ||
JavaPairRDD<MatrixIndexes, CompressedWriteBlock> cmbRdd, JavaPairRDD<DictWritable.K, DictWritable> dictsRdd) { | ||
// combine the elements | ||
JavaPairRDD<MatrixIndexes, MatrixBlock> mbrdd = cmbRdd.mapValues(new CompressUnwrap()); | ||
JavaPairRDD<Integer, List<IDictionary>> dictsUnpacked = dictsRdd | ||
.mapToPair((t) -> new Tuple2<>(Integer.valueOf(t._1.id + 1), t._2.dicts)); | ||
JavaPairRDD<Integer, Tuple2<MatrixIndexes, MatrixBlock>> mbrddC = mbrdd | ||
.mapToPair((t) -> new Tuple2<>(Integer.valueOf((int) t._1.getColumnIndex()), t)); | ||
|
||
JavaPairRDD<Integer, Tuple2<Tuple2<MatrixIndexes, MatrixBlock>, List<IDictionary>>> j = mbrddC | ||
.join(dictsUnpacked); | ||
|
||
JavaPairRDD<MatrixIndexes, MatrixBlock> ret = j.mapToPair(ReaderSparkCompressed::combineTuples); | ||
return ret; | ||
} | ||
|
||
private static Tuple2<MatrixIndexes, MatrixBlock> combineTuples( | ||
Tuple2<Integer, Tuple2<Tuple2<MatrixIndexes, MatrixBlock>, List<IDictionary>>> e) { | ||
MatrixIndexes kOut = e._2._1._1; | ||
MatrixBlock mbIn = e._2._1._2; | ||
List<IDictionary> dictsIn = e._2._2; | ||
MatrixBlock ob = combineMatrixBlockAndDict(mbIn, dictsIn); | ||
return new Tuple2<>(kOut, ob); | ||
} | ||
|
||
private static MatrixBlock combineMatrixBlockAndDict(MatrixBlock mb, List<IDictionary> dicts) { | ||
if(mb instanceof CompressedMatrixBlock) { | ||
CompressedMatrixBlock cmb = (CompressedMatrixBlock) mb; | ||
List<AColGroup> gs = cmb.getColGroups(); | ||
|
||
if(dicts.size() == gs.size()) { | ||
for(int i = 0; i < dicts.size(); i++) | ||
gs.set(i, ((ADictBasedColGroup) gs.get(i)).copyAndSet(dicts.get(i))); | ||
} | ||
else { | ||
LOG.error(dicts.size()); | ||
LOG.error(gs.size()); | ||
int gis = 0; | ||
for(int i = 0; i < gs.size(); i++) { | ||
AColGroup g = gs.get(i); | ||
if(g instanceof ADictBasedColGroup) { | ||
ADictBasedColGroup dg = (ADictBasedColGroup) g; | ||
gs.set(i, dg.copyAndSet(dicts.get(gis))); | ||
gis++; | ||
} | ||
} | ||
} | ||
|
||
return new CompressedMatrixBlock(cmb.getNumRows(), cmb.getNumColumns(), cmb.getNonZeros(), | ||
cmb.isOverlapping(), gs); | ||
} | ||
else | ||
return mb; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.