Skip to content

Commit 6d65027

Browse files
committed
Do not try to compress variable-sized varaibles
Fixes #1420
1 parent 2d214b7 commit 6d65027

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cdm/core/src/main/java/ucar/nc2/write/Nc4ChunkingStrategy.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
package ucar.nc2.write;
77

8+
import ucar.ma2.DataType;
89
import ucar.nc2.Attribute;
10+
import ucar.nc2.Structure;
911
import ucar.nc2.Variable;
1012
import ucar.nc2.constants.CDM;
1113
import javax.annotation.concurrent.Immutable;
@@ -52,7 +54,20 @@ protected Nc4ChunkingStrategy(int deflateLevel, boolean shuffle) {
5254

5355
@Override
5456
public int getDeflateLevel(Variable v) {
55-
return deflateLevel;
57+
return isCompressible(v) ? deflateLevel : 0;
58+
}
59+
60+
// compression should not be applied to variable-sized variables
61+
// see Unidata/netcdf-java#1420
62+
private boolean isCompressible(Variable v) {
63+
if (v.getDataType().equals(DataType.STRING) || v.isVariableLength())
64+
return false;
65+
66+
if (v.getDataType().equals(DataType.STRUCTURE)) {
67+
Structure s = (Structure) v;
68+
return s.getVariables().stream().allMatch(this::isCompressible);
69+
}
70+
return true;
5671
}
5772

5873
@Override

0 commit comments

Comments
 (0)