Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion java/vector/src/main/codegen/templates/ComplexWriters.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ public void write(Nullable${minor.class}Holder h) {
vector.setValueCount(idx()+1);
}

<#if minor.class == "Decimal">
<#if minor.class == "Decimal" ||
minor.class == "VarChar">
public void write${minor.class}(${friendlyType} value) {
vector.setSafe(idx(), value);
vector.setValueCount(idx()+1);
}
</#if>

<#if minor.class == "Decimal">
public void writeBigEndianBytesToDecimal(byte[] value) {
vector.setBigEndianSafe(idx(), value);
vector.setValueCount(idx()+1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,29 @@ public void setSafe(int index, NullableVarCharHolder holder) {
lastSet = index;
}

/**
* Set the variable length element at the specified index to the
* content in supplied Text
*
* @param index position of the element to set
* @param text Text object with data
*/
public void set(int index, Text text) {
set(index, text.getBytes(), 0, text.getLength());
}

/**
* Same as {@link #set(int, NullableVarCharHolder)} except that it handles the
* case where index and length of new element are beyond the existing
* capacity of the vector.
*
* @param index position of the element to set.
* @param text Text object with data
*/
public void setSafe(int index, Text text) {
setSafe(index, text.getBytes(), 0, text.getLength());
}


/******************************************************************
* *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.arrow.vector.types.pojo.Schema;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.util.Text;
import org.apache.arrow.vector.util.TransferPair;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -885,6 +886,10 @@ public void testNullableVarType1() {
vector.setSafe(5, STR3ByteBuffer, 1, STR3.length - 1);
vector.setSafe(6, STR3ByteBuffer, 2, STR3.length - 2);

// Set with convenience function
Text txt = new Text("foo");
vector.setSafe(7, txt);

// Check the sample strings.
assertArrayEquals(STR1, vector.get(0));
assertArrayEquals(STR2, vector.get(1));
Expand All @@ -894,10 +899,13 @@ public void testNullableVarType1() {
assertArrayEquals(Arrays.copyOfRange(STR3, 1, STR3.length), vector.get(5));
assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), vector.get(6));

// Check returning a Text object
assertEquals(txt, vector.getObject(7));

// Ensure null value throws.
boolean b = false;
try {
vector.get(7);
vector.get(8);
} catch (IllegalStateException e) {
b = true;
} finally {
Expand Down