-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-18014: [Java] Implement copy functions for vectors and Table #14389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,10 @@ public BaseTable(List<FieldVector> fieldVectors, int rowCount, DictionaryProvide | |
| this.schema = new Schema(fields); | ||
| } | ||
|
|
||
| BaseTable() { | ||
| this.fieldVectors = new ArrayList<>(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a FieldReader for the vector with the given name. | ||
| * | ||
|
|
@@ -254,7 +258,7 @@ FieldVector getVector(String columnName) { | |
| return entry.getValue(); | ||
| } | ||
| } | ||
| throw new IllegalStateException(String.format("No vector named '%s' is present in the table", columnName)); | ||
| throw new IllegalArgumentException(String.format("No vector named '%s' is present in the table", columnName)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -266,6 +270,48 @@ FieldVector getVector(int columnIndex) { | |
| return fieldVectors.get(columnIndex); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns a copy of the vector with the given name, or throws IllegalArgumentException if the name is not found. | ||
| * Names are case-sensitive. | ||
| * | ||
| * @param columnName The name of the vector to copy | ||
| * @return A copy of the Vector with the given name | ||
| * @throws IllegalArgumentException if the name is not the name of a vector in the table. | ||
| */ | ||
| public FieldVector getVectorCopy(String columnName) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a doubt, Is there some base/abstract object that For example, this method could be helpful in both sides Tables and VectorSchemaRoot If by design this was created independently please let me know to consider that at the moment to read *.table package
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There's no abstract class as VSR doesn't inherit from anything. I have considered adding an interface at some point that they both could implement to make it easier to swap one for the other.
I'm not sure I understand this part of the comment.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok, thank you.
This is related with the 1st question that initially VSR and Table are growing independently and at some point they both could implement the same contract.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks. |
||
| FieldVector source; | ||
| for (Map.Entry<Field, FieldVector> entry : fieldVectorsMap.entrySet()) { | ||
| if (entry.getKey().getName().equals(columnName)) { | ||
| source = entry.getValue(); | ||
| FieldVector copy = source.getField().createVector(source.getAllocator()); | ||
| copy.allocateNew(); | ||
| for (int i = 0; i < source.getValueCount(); i++) { | ||
| copy.copyFromSafe(i, i, source); | ||
| } | ||
| copy.setValueCount(source.getValueCount()); | ||
| return copy; | ||
| } | ||
| } | ||
| throw new IllegalStateException(String.format("No vector named '%s' is present in the table", columnName)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of the vector at the given position. | ||
| * | ||
| * @param columnIndex The 0-based position of the vector to be copied | ||
| */ | ||
| public FieldVector getVectorCopy(int columnIndex) { | ||
| FieldVector source = fieldVectors.get(columnIndex); | ||
| FieldVector copy = source.getField().createVector(source.getAllocator()); | ||
| copy.allocateNew(); | ||
| for (int i = 0; i < source.getValueCount(); i++) { | ||
| copy.copyFromSafe(i, i, source); | ||
| } | ||
| copy.setValueCount(source.getValueCount()); | ||
| return copy; | ||
| } | ||
|
|
||
| /** | ||
| * Returns an immutable Row object holding a reference to this table. The default character | ||
| * encoding used by the cursor to decode Strings will be StandardCharsets.UTF_8 as this is the only charset | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the exception class is different from what's actually thrown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix the exception class issue. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done