Skip to content

Commit d37b6fd

Browse files
committed
Adds the --ion-use-big-decimals option.
1 parent 4447fa7 commit d37b6fd

File tree

8 files changed

+64
-4
lines changed

8 files changed

+64
-4
lines changed

src/com/amazon/ion/benchmark/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Constants {
1818
static final String ION_USE_SYMBOL_TOKENS_NAME = "k";
1919
static final String ION_FLOAT_WIDTH_NAME = "W";
2020
static final String ION_USE_LOB_CHUNKS_NAME = "e";
21+
static final String ION_USE_BIG_DECIMALS_NAME = "D";
2122
static final String PATHS_NAME = "s";
2223
static final String ION_WRITER_BLOCK_SIZE_NAME = "b";
2324
static final String AUTO_VALUE = "auto";

src/com/amazon/ion/benchmark/IonMeasurableReadTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ private void consumeCurrentValue(IonReader reader, boolean isInStruct) {
128128
reader.doubleValue();
129129
break;
130130
case DECIMAL:
131-
reader.decimalValue();
131+
if (options.useBigDecimals) {
132+
reader.bigDecimalValue();
133+
} else {
134+
reader.decimalValue();
135+
}
132136
break;
133137
case TIMESTAMP:
134138
reader.timestampValue();

src/com/amazon/ion/benchmark/Main.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Main {
3838
+ "[--ion-api <api>]... [--ion-imports-for-input <file>] [--ion-imports-for-benchmark <file>]... "
3939
+ "[--ion-flush-period <int>]... [--ion-length-preallocation <int>]... [--ion-float-width <int>]... "
4040
+ "[--ion-use-symbol-tokens <bool>]... [--paths <file>] [--ion-reader <type>]... "
41-
+ "[--ion-use-lob-chunks <bool>]... <input_file>\n"
41+
+ "[--ion-use-lob-chunks <bool>]... [--ion-use-big-decimals <bool>]... <input_file>\n"
4242

4343
+ " ion-java-benchmark --help\n"
4444

@@ -66,8 +66,6 @@ public class Main {
6666
+ "world to ensure the initialization cost is properly amortized.\n"
6767
+ "\n";
6868

69-
// TODO add options for the following:
70-
// TODO read decimals using bigDecimalValue() instead of decimalValue()
7169
private static final String OPTIONS =
7270
"Options:\n"
7371

@@ -211,6 +209,11 @@ public class Main {
211209
+ "is ion_binary or ion_text and --ion-api streaming is used. May be specified twice to compare both "
212210
+ "settings. [default: false]\n"
213211

212+
+ " -D --ion-use-big-decimals <bool> When true, read Ion decimal values into BigDecimal instances. When "
213+
+ "false, read decimal values into Decimal instances, which are capable of conveying negative zero. "
214+
+ "Ignored unless one of the specified formats is ion_binary or ion_text and --ion-api streaming is used. "
215+
+ "May be specified twice to compare both settings. [default: false]\n"
216+
214217
+ "\n";
215218

216219
private static final String EXAMPLES =

src/com/amazon/ion/benchmark/ReadOptionsCombination.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414

1515
import static com.amazon.ion.benchmark.Constants.ION_READER_NAME;
16+
import static com.amazon.ion.benchmark.Constants.ION_USE_BIG_DECIMALS_NAME;
1617
import static com.amazon.ion.benchmark.Constants.ION_USE_LOB_CHUNKS_NAME;
1718
import static com.amazon.ion.benchmark.Constants.PATHS_NAME;
1819

@@ -24,6 +25,7 @@ class ReadOptionsCombination extends OptionsCombinationBase {
2425
final List<String> paths;
2526
final IonReaderType readerType;
2627
final boolean useLobChunks;
28+
final boolean useBigDecimals;
2729

2830
/**
2931
* @param serializedOptionsCombination text Ion representation of the options combination.
@@ -52,6 +54,7 @@ class ReadOptionsCombination extends OptionsCombinationBase {
5254
IonReaderType.NON_BLOCKING
5355
);
5456
useLobChunks = getOrDefault(optionsCombinationStruct, ION_USE_LOB_CHUNKS_NAME, val -> ((IonBool) val).booleanValue(), false);
57+
useBigDecimals = getOrDefault(optionsCombinationStruct, ION_USE_BIG_DECIMALS_NAME, val -> ((IonBool) val).booleanValue(), false);
5558
}
5659

5760
@Override

src/com/amazon/ion/benchmark/ReadOptionsMatrix.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static com.amazon.ion.benchmark.Constants.ION_READER_NAME;
99
import static com.amazon.ion.benchmark.Constants.ION_SYSTEM;
10+
import static com.amazon.ion.benchmark.Constants.ION_USE_BIG_DECIMALS_NAME;
1011
import static com.amazon.ion.benchmark.Constants.ION_USE_LOB_CHUNKS_NAME;
1112
import static com.amazon.ion.benchmark.Constants.PATHS_NAME;
1213

@@ -46,6 +47,14 @@ void parseCommandSpecificOptions(Map<String, Object> optionsMatrix, List<IonStru
4647
optionsCombinationStructs,
4748
() -> ION_SYSTEM.newBool(false)
4849
);
50+
parseAndCombine(
51+
optionsMatrix.get("--ion-use-big-decimals"),
52+
ION_USE_BIG_DECIMALS_NAME,
53+
OptionsMatrixBase::getTrueOrNull,
54+
ION_SYSTEM::newBool,
55+
optionsCombinationStructs,
56+
() -> ION_SYSTEM.newBool(false)
57+
);
4958
}
5059

5160
}

tst/com/amazon/ion/benchmark/OptionsTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private static class ExpectedReadOptionsCombination
169169
List<String> paths = null;
170170
IonReaderType readerType = IonReaderType.NON_BLOCKING;
171171
boolean useLobChunks = false;
172+
boolean useBigDecimals = false;
172173

173174
static ExpectedReadOptionsCombination defaultOptions() {
174175
return new ExpectedReadOptionsCombination();
@@ -189,12 +190,18 @@ final ExpectedReadOptionsCombination useLobChunks(boolean useLobChunks) {
189190
return this;
190191
}
191192

193+
final ExpectedReadOptionsCombination useBigDecimals(boolean useBigDecimals) {
194+
this.useBigDecimals = useBigDecimals;
195+
return this;
196+
}
197+
192198
@Override
193199
void assertOptionsEqual(ReadOptionsCombination that) {
194200
super.assertOptionsEqual(that);
195201
assertEquals(paths, that.paths);
196202
assertEquals(readerType, that.readerType);
197203
assertEquals(useLobChunks, that.useLobChunks);
204+
assertEquals(useBigDecimals, that.useBigDecimals);
198205
}
199206
}
200207

@@ -1218,4 +1225,36 @@ public void readUsingLogChunks() throws Exception {
12181225
assertTrue(expectedCombinations.isEmpty());
12191226
}
12201227

1228+
@Test
1229+
public void readUsingBigDecimals() throws Exception {
1230+
List<ReadOptionsCombination> optionsCombinations = parseOptionsCombinations(
1231+
"read",
1232+
"--ion-use-big-decimals",
1233+
"true",
1234+
"--ion-use-big-decimals",
1235+
"false",
1236+
"--format",
1237+
"ion_text",
1238+
"--format",
1239+
"ion_binary",
1240+
"binaryLargeLobs.10n"
1241+
);
1242+
assertEquals(4, optionsCombinations.size());
1243+
List<ExpectedReadOptionsCombination> expectedCombinations = new ArrayList<>(4);
1244+
1245+
expectedCombinations.add(ExpectedReadOptionsCombination.defaultOptions().useBigDecimals(true).format(Format.ION_TEXT));
1246+
expectedCombinations.add(ExpectedReadOptionsCombination.defaultOptions().useBigDecimals(false).format(Format.ION_TEXT));
1247+
expectedCombinations.add(ExpectedReadOptionsCombination.defaultOptions().useBigDecimals(true).format(Format.ION_BINARY));
1248+
expectedCombinations.add(ExpectedReadOptionsCombination.defaultOptions().useBigDecimals(false).format(Format.ION_BINARY));
1249+
1250+
for (ReadOptionsCombination optionsCombination : optionsCombinations) {
1251+
expectedCombinations.removeIf(candidate -> candidate.useBigDecimals == optionsCombination.useBigDecimals && candidate.format == optionsCombination.format);
1252+
1253+
assertReadTaskExecutesCorrectly("binaryAllTypes.10n", optionsCombination, optionsCombination.format, optionsCombination.format == Format.ION_TEXT);
1254+
assertReadTaskExecutesCorrectly("textAllTypes.ion", optionsCombination, optionsCombination.format, optionsCombination.format == Format.ION_BINARY);
1255+
}
1256+
1257+
assertTrue(expectedCombinations.isEmpty());
1258+
}
1259+
12211260
}
3 Bytes
Binary file not shown.

tst/com/amazon/ion/benchmark/textAllTypes.ion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ false
2121
1.23e4
2222
-1.23e-4
2323
0.00001
24+
-0d0
2425
-1.0d23
2526
2000-01-01T00:00:00Z
2627
{{ aGVsbG8= }}

0 commit comments

Comments
 (0)