Repository: orc Updated Branches: refs/heads/master ec905da4d -> b9aec432e
Fixes #183 Signed-off-by: Deepak Majeti <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/orc/repo Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/b9aec432 Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/b9aec432 Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/b9aec432 Branch: refs/heads/master Commit: b9aec432e2b322fcea1856da5beceda7ee686c4a Parents: ec905da Author: Gang Wu <[email protected]> Authored: Tue Oct 24 15:15:12 2017 -0700 Committer: Deepak Majeti <[email protected]> Committed: Mon Oct 30 22:32:08 2017 -0400 ---------------------------------------------------------------------- c++/src/Vector.cc | 2 +- c++/test/TestDecimal.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/orc/blob/b9aec432/c++/src/Vector.cc ---------------------------------------------------------------------- diff --git a/c++/src/Vector.cc b/c++/src/Vector.cc index 811bcac..688855a 100644 --- a/c++/src/Vector.cc +++ b/c++/src/Vector.cc @@ -391,7 +391,7 @@ namespace orc { scale = 0; }else{ std::string copy(str); - scale = static_cast<int32_t>(str.length() - foundPoint); + scale = static_cast<int32_t>(str.length() - foundPoint - 1); value = Int128(copy.replace(foundPoint, 1, "")); } } http://git-wip-us.apache.org/repos/asf/orc/blob/b9aec432/c++/test/TestDecimal.cc ---------------------------------------------------------------------- diff --git a/c++/test/TestDecimal.cc b/c++/test/TestDecimal.cc index 87a5dd1..3ed6020 100644 --- a/c++/test/TestDecimal.cc +++ b/c++/test/TestDecimal.cc @@ -107,4 +107,48 @@ namespace orc { Decimal(Int128::minimumValue(), 39))); } + TEST(Decimal, testString2Decimal) { + // no decimal point + Decimal decimal1("12345"); + EXPECT_EQ(Int128(12345), decimal1.value); + EXPECT_EQ(0, decimal1.scale); + + Decimal decimal2("0"); + EXPECT_EQ(Int128(0), decimal2.value); + EXPECT_EQ(0, decimal2.scale); + + Decimal decimal3("99999999999999999999999999999999999999"); + EXPECT_EQ(Int128("99999999999999999999999999999999999999"), decimal3.value); + EXPECT_EQ(0, decimal3.scale); + + Decimal decimal4("-99999999999999999999999999999999999999"); + EXPECT_EQ(Int128("-99999999999999999999999999999999999999"), decimal4.value); + EXPECT_EQ(0, decimal4.scale); + + Decimal decimal5("-12345"); + EXPECT_EQ(Int128(-12345), decimal5.value); + EXPECT_EQ(0, decimal5.scale); + + // has decimal point + Decimal decimal6("12345.12345"); + EXPECT_EQ(Int128("1234512345"), decimal6.value); + EXPECT_EQ(5, decimal6.scale); + + Decimal decimal7("0.0"); + EXPECT_EQ(Int128(0), decimal7.value); + EXPECT_EQ(1, decimal7.scale); + + Decimal decimal8("999999999999999999999999999999.99999999"); + EXPECT_EQ(Int128("99999999999999999999999999999999999999"), decimal8.value); + EXPECT_EQ(8, decimal8.scale); + + Decimal decimal9("-999999999999999999999999999999.99999999"); + EXPECT_EQ(Int128("-99999999999999999999999999999999999999"), decimal9.value); + EXPECT_EQ(8, decimal9.scale); + + Decimal decimal10("-123.45"); + EXPECT_EQ(Int128(-12345), decimal10.value); + EXPECT_EQ(2, decimal10.scale); + } + }
