You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cu...@apache.org on 2019/06/27 19:36:50 UTC
[arrow] branch master updated: ARROW-5435: [Java] Add test for
IntervalYearVector#getAsStringBuilder
This is an automated email from the ASF dual-hosted git repository.
cutlerb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 424dccf ARROW-5435: [Java] Add test for IntervalYearVector#getAsStringBuilder
424dccf is described below
commit 424dccfc364d67ab530b6b02c559c3273eddb885
Author: tianchen <ni...@alibaba-inc.com>
AuthorDate: Thu Jun 27 12:36:41 2019 -0700
ARROW-5435: [Java] Add test for IntervalYearVector#getAsStringBuilder
Related to [ARROW-5435](https://issues.apache.org/jira/browse/ARROW-5435).
This adds a test for `IntervalYearVector.getAsStringBuilder`.
Author: tianchen <ni...@alibaba-inc.com>
Closes #4407 from tianchen92/ARROW-5435 and squashes the following commits:
d663640 <tianchen> fix test
932f5f5 <tianchen> fix getAsStringBuilder
f73b2fe <tianchen> style check
36dcebb <tianchen> ARROW-5435: IntervalYearVector#getObject should return Period with both year and month
---
.../apache/arrow/vector/IntervalYearVector.java | 8 +--
.../arrow/vector/TestIntervalYearVector.java | 58 ++++++++++++++++++++++
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java
index ee19ba6..6d8c001 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java
@@ -178,10 +178,10 @@ public class IntervalYearVector extends BaseFixedWidthVector {
final String monthString = (Math.abs(months) == 1) ? " month " : " months ";
return (new StringBuilder()
- .append(years)
- .append(yearString)
- .append(months)
- .append(monthString));
+ .append(years)
+ .append(yearString)
+ .append(months)
+ .append(monthString));
}
/**
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java
new file mode 100644
index 0000000..5ea48b4
--- /dev/null
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.vector;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestIntervalYearVector {
+
+ private BufferAllocator allocator;
+
+ @Before
+ public void init() {
+ allocator = new DirtyRootAllocator(Long.MAX_VALUE, (byte) 100);
+ }
+
+ @After
+ public void terminate() throws Exception {
+ allocator.close();
+ }
+
+ @Test
+ public void testGetAsStringBuilder() {
+ try (final IntervalYearVector vector = new IntervalYearVector("", allocator)) {
+ int valueCount = 100;
+ vector.setInitialCapacity(valueCount);
+ vector.allocateNew();
+ for (int i = 0; i < valueCount; i++) {
+ vector.set(i, i);
+ }
+
+ assertEquals("0 years 1 month ", vector.getAsStringBuilder(1).toString());
+ assertEquals("0 years 10 months ", vector.getAsStringBuilder(10).toString());
+ assertEquals("1 year 8 months ", vector.getAsStringBuilder(20).toString());
+ assertEquals("2 years 6 months ", vector.getAsStringBuilder(30).toString());
+
+ }
+ }
+}