ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated) - #1492

Closed
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634
Closed

ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)#1492
alphalfalfa wants to merge 7 commits into
apache:masterfrom
alphalfalfa:updated-arrow-633-634

Conversation

@alphalfalfa

Copy link
Copy Markdown
Contributor

The original PR is at #1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.

Changes include:

  • Arrow-633: [Java] Add support for FixedWidthBinary type
  • Arrow-634: Add integration tests for FixedSizeBinary

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed the derived vector classes to use integer type. Should I?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TYPE_WIDTH const in the subclass is a static variable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other types, they can be static, for fixed size binary, it has to be non-static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@wesm@icexelloss

if (isSet(index) == 0) {
return null;
} else {
return get(index);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this function to avoid duplicate check?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expanded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't see the change. Did you push the change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. This looks good now.

if (byteWidth == 0) {
byteWidth = value.length;
} else if (byteWidth != value.length) {
throw new IOException("mismatch byte width (" + value.length + ") at index " + i + ", expecting " + byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the input is malformatted? If this is, then it probably shouldn't be IOException..

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to RuntimeException

}
}
if (count > 0 && byteWidth == 0) {
throw new IOException("could not determine the byte width of the vector because all elements are null");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RuntimeException

values.add(value);
if (value.length > 0) {
if (byteWidth == 0) {
byteWidth = value.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you read the byteWidth from the schema rather than interpret it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteWidth info is now collected from the vector and passed in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am not sure I understand.. Why don't we use the byteWidth in schema to inform the expected length here?


ArrowBuf buf = allocator.buffer(byteWidth * count);
for (byte[] value : values) {
buf.writeBytes(value.length == 0? new byte[byteWidth] : value);

@icexellossicexellossJan 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can there be empty values?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nullable vectors, when the value is null, the corresponding JSON field is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

* @param index position of the element to set
* @param holder holder that carries data buffer.
*/
public void set(int index, NullableFixedSizeBinaryHolder holder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this FixedSizeBinaryHolder instead?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are both Holders and NullableHolders.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

to.copyFromSafe(fromIndex, toIndex, FixedSizeBinaryVector.this);
}
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@icexelloss

Copy link
Copy Markdown
Contributor

High level looks good to me. Need to come back and look in more detail.

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

Anybody knows what should I do with the check failure:

The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-4.9 g++-4.9 gdb ccache valgrind libboost-dev libboost-filesystem-dev libboost-system-dev libjemalloc-dev gtk-doc-tools autoconf-archive libgirepository1.0-dev" failed and exited with 100 during .

Also, more comments on this PR?

@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia or @BryanCutler Could one of you please also take a look? Thanks!

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

@alphalfalfa we've been experiencing a lot of apt flakiness in Travis CI. Someone should escalate it with the support system to see what's going on

@wesm

wesm commented Jan 23, 2018

Copy link
Copy Markdown
Member

I just restarted the failing job

BufferReader INT8 = new BufferReader() {
@Override
protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException {
protected ArrowBuf read(BufferAllocator allocator, int count, int byteWidth) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I am not sure about this. Having byteWidth in every reader seems weird because most don't need it. Can you put make a member variable of fixed size binary reader?

Comment threadintegration/integration_test.py Outdated
def _get_buffers(self):
data = []
for i, v in enumerate(self.values):
data.append(self._encode_value(v if self.is_valid[i] else ""))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange. Why are we using empty string to represent null value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just use any value for null instead of empty string. It should make the logic cleaner. (less if statements)

@alphalfalfaalphalfalfaJan 23, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I put empty strings as null. sure, i can put some arbitrary strings

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes and simplified the logic inside JsonFileReader

if (bufferType.equals(DATA) && (vector.getMinorType() == Types.MinorType.VARCHAR ||
vector.getMinorType() == Types.MinorType.VARBINARY)) {
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale);
writeValueToGenerator(bufferType, vectorBuffer, vectorBuffers.get(v-1), vector, i, scale, byteWidth);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't need to take scale and byteWidth. It can figure this out from vector.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, modified.

@wesm

wesm commented Jan 29, 2018

Copy link
Copy Markdown
Member

@siddharthteotia@jacques-n could we get some more eyes on this? Thanks!

@BryanCutlerBryanCutler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alphalfalfa , looks pretty good! I just had some minor suggestions

Comment threadintegration/integration_test.py Outdated
class FixedSizeBinaryType(PrimitiveType):

def __init__(self, name, byte_width, nullable=True):
PrimitiveType.__init__(self, name, nullable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think super(..).__init__(..) is a little better

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public abstract class BaseFixedWidthVector extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final byte typeWidth;
private final int typeWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you can update BitVector since it currently casts down to a byte


@Override
public TypeLayout visit(FixedSizeBinary type) {
return newFixedWidthTypeLayout(BufferLayout.dataBuffer(type.getByteWidth() * 8));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just do?

return newFixedWidthTypeLayout(new BufferLayout(BufferType.DATA, type.getByteWidth() * 8)

Then you don't need to BufferLayout dataBuffer(int typeBitWidth)
and then keep the

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return VALUES_128;
default:
throw new IllegalArgumentException("only 8, 16, 32, or 64 bits supported");
return new BufferLayout(BufferType.DATA, typeBitWidth);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function is really "get data buffer layout for types that support certain bit widths" - so it might be beneficial to keep the exception, although it looks like it should be updated to include 128. I'm not sure how exactly the exception would be thrown, but if somehow a buffer layout for an Int with 30 bit width was created, this would catch it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted and added 128 bits to the exception message

values.add(value);
}

int byteWidth = count > 0? values.get(0).length : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add space before ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

…ng dataBuffer() method and some other changes based on PR comments
@icexelloss

Copy link
Copy Markdown
Contributor

@siddharthteotia Do you think we can merge this? LGTM but want to double check with you.

@wesmwesm changed the title ARROW-633/634: Add FixedSizeBinary support in Java and integration tests (Updated)ARROW-633/634: [Java] Add FixedSizeBinary support in Java and integration tests (Updated)Feb 5, 2018
@jacques-n

Copy link
Copy Markdown
Contributor

It seems like we are missing support in the ComplexWriter and FieldReader interfaces. I think that should be included in introduction of these things. The patch here looks fine but I think we should include that before releasing this feature (either in this patch or a follow-up).

@jacques-n

Copy link
Copy Markdown
Contributor

Per my comment, I'm +1 on the spirit on these changes but think the patch (or feature) is somewhat incomplete

@alphalfalfa

Copy link
Copy Markdown
ContributorAuthor

@jacques-n, to make sure that I understand the question properly, do you mean there should be proper interfaces defined for FixedSizeBinary type inside AbstractFieldWriter and AbstractFieldReader?
Currently, AbstractFieldWriter has:
public void writeFixedSizeBinary(ArrowBuf buffer)
AbstractFieldReaderWriter has:
public byte[] readByteArray()
What would be the desired interfaces to add?

I would prefer to add the necessary fix in a separate PR as this one has grown too big if it is OK.

@jacques-n

Copy link
Copy Markdown
Contributor

You're right. I forgot that the code is autogenerated and was looking for it here. I'm +1 on this PR.

@wesm

wesm commented Feb 7, 2018

Copy link
Copy Markdown
Member

thanks all, please open any follow-up JIRAs

@wesmwesm closed this in f69e9dbFeb 7, 2018
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…tion tests (Updated)
The original PR is at apache#1012. Due to the major refactoring last year, changes are big. So I created this separate PR for easier to review and will cancel the other one later.
Changes include:
* Arrow-633: [Java] Add support for FixedWidthBinary type
* Arrow-634: Add integration tests for FixedSizeBinary
Author: Jingyuan Wang <jingyuan@live.com>
Author: jingyuan <jingyuan.nt@gmail.com>
Closesapache#1492 from alphalfalfa/updated-arrow-633-634 and squashes the following commits:
c994a19 [jingyuan] create data buffer layout for FixedSizeBinary directly instead of using dataBuffer() method and some other changes based on PR comments
873c5b2 [jingyuan] do not pass scale or byteWidth into writeValueToGenerator in JsonFileWriter.java
4fbb67d [jingyuan] put arbitrary values for FixSizeBinary nulls
0c0015d [Jingyuan Wang] add a new line
a8a9553 [Jingyuan Wang] Pass byteWidth info for FixedSizeBinary type in JsonFileReader
1a64c5c [Jingyuan Wang] expand get() method inside getObject() method to remove duplicate check of isSet()
071fb25 [Jingyuan Wang] ARROW-633/634: Add FixedSizeBinary support in Java and integration tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@alphalfalfa@icexelloss@wesm@jacques-n@BryanCutler