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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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.
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*/
public FieldVector getVectorCopy(String columnName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a doubt, Is there some base/abstract object that Table and VectorShemaRoot share?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a doubt, Is there some base/abstract object that Table and VectorShemaRoot share?

For example, this method could be helpful in both sides Tables and VectorSchemaRoot

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.

If by design this was created independently please let me know to consider that at the moment to read *.table package

I'm not sure I understand this part of the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Ok, thank you.

I'm not sure I understand this part of the comment.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Thanks.
Given the possibility of someday having a shared interface, I have tried to write similar methods using the same method signature as much as possible.

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
Expand Down
Loading