Skip to content

Commit 5b71a03

Browse files
committed
[SYSTEMDS-3813] Fix incorrect file format on list write
The writing of lists always produced individual matrix/frame files in text format (even though the metadata of the list indicated otherwise). This patch now properly writes the individual files in the correct format.
1 parent 06ad1b5 commit 5b71a03

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/main/java/org/apache/sysds/lops/Data.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,10 @@ else if (_op.isWrite()) {
276276
OutputParameters oparams = getOutputParameters();
277277
if ( _op.isWrite() ) {
278278
sb.append( OPERAND_DELIMITOR );
279-
FileFormat fmt = null;
280-
if ( getDataType() == DataType.MATRIX || getDataType() == DataType.FRAME )
281-
fmt = oparams.getFormat();
282-
else // scalars will always be written in text format
283-
fmt = FileFormat.TEXT;
284-
279+
// scalars will always be written in text format
280+
FileFormat fmt = getDataType().isScalar() ?
281+
FileFormat.TEXT : oparams.getFormat();
282+
285283
//format literal or variable
286284
Lop fmtLop = _inputParams.get(DataExpression.FORMAT_TYPE);
287285
String fmtLabel = (fmt!=FileFormat.UNKNOWN) ? fmt.toString() : fmtLop.getOutputParameters().getLabel();

src/main/java/org/apache/sysds/runtime/instructions/cp/VariableCPInstruction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ else if( getInput1().getDataType() == DataType.TENSOR ) {
10841084
}
10851085
else if( getInput1().getDataType() == DataType.LIST ) {
10861086
ListObject lo = ec.getListObject(getInput1().getName());
1087-
ListWriter.writeListToHDFS(lo, fname, fmtStr, _formatProperties);
1087+
int blen = Integer.parseInt(getInput4().getName());
1088+
ListWriter.writeListToHDFS(lo, fname, fmtStr, new FileFormatProperties(blen));
10881089
}
10891090
}
10901091

src/test/java/org/apache/sysds/test/functions/io/ReadWriteListTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.commons.logging.LogFactory;
2626
import org.apache.sysds.common.Types.ExecMode;
2727
import org.apache.sysds.common.Types.FileFormat;
28+
import org.apache.sysds.runtime.meta.MetaDataAll;
2829
import org.apache.sysds.runtime.util.HDFSTool;
2930
import org.apache.sysds.test.AutomatedTestBase;
3031
import org.apache.sysds.test.TestConfiguration;
@@ -120,8 +121,14 @@ private void runListReadWriteTest(boolean named, FileFormat format, ExecMode mod
120121
fullDMLScriptName = HOME + TEST_NAME2 + ".dml";
121122
programArgs = new String[]{"-args", output("L"), output("R2")};
122123
runTest(true, false, null, -1);
123-
double val2 = HDFSTool.readDoubleFromHDFSFile(output("R2"));
124124

125+
//check meta data, incl implicitly format
126+
MetaDataAll meta = getMetaData("L", OUTPUT_DIR);
127+
Assert.assertEquals(format.toString(), meta.getFormatTypeString());
128+
Assert.assertEquals(4, meta.getDim1());
129+
Assert.assertEquals(1, meta.getDim2());
130+
131+
double val2 = HDFSTool.readDoubleFromHDFSFile(output("R2"));
125132
Assert.assertEquals(Double.valueOf(val1), Double.valueOf(val2), eps);
126133
}
127134
catch(IOException e) {

0 commit comments

Comments
 (0)