GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing arrow.apache.org — Table - arrow-java 19.0.0 documentation Table¶NOTE: The Table API is experimental and subject to change. See the list of limitations below. Table is an immutable tabular data structure based on FieldVector. Like VectorSchemaRoot, Mutation in Table and VectorSchemaRoot¶
The rules aren’t enforced by the API so the programmer is responsible for ensuring that they are followed. Failure to do so could lead to runtime exceptions.
Features and limitations¶A basic set of table functionality is currently available:
Limitations in the 11.0.0 release:
The Table API¶Like Creating a Table from a VectorSchemaRoot¶Tables are created from a Table t = new Table(someVectorSchemaRoot); If you now update the vectors held by the Creating a Table from FieldVectors¶Tables can be created from IntVector myVector = createMyIntVector(); VectorSchemaRoot vsr1 = new VectorSchemaRoot(myVector); or by passing a collection: IntVector myVector = createMyIntVector(); List<FieldVector> fvList = List.of(myVector); VectorSchemaRoot vsr1 = new VectorSchemaRoot(fvList); It is rarely a good idea to share vectors between multiple vector schema roots, and it would not be a good idea to share them between vector schema roots and tables. Creating a Don’t do this: IntVector myVector = createMyIntVector(); // Reference count for myVector = 1 VectorSchemaRoot vsr1 = new VectorSchemaRoot(myVector); // Still one reference VectorSchemaRoot vsr2 = new VectorSchemaRoot(myVector); // Ref count is still one, but there are two VSRs with a reference to myVector vsr2.clear(); // Reference count for myVector is 0. What is happening is that the reference counter works at a lower level than the When you create tables from vectors, it’s assumed that there are no external references to those vectors. To be certain, the buffers underlying these vectors are transferred to new vectors in the new table, and the original vectors are cleared. Don’t do this either, but note the difference from above: IntVector myVector = createMyIntVector(); // Reference count for myVector = 1 Table t1 = new Table(myVector); // myVector is cleared; Table t1 has a new hidden vector with the data from myVector Table t2 = new Table(myVector); // t2 has no rows because myVector was just cleared // t1 continues to have the data from the original vector t2.clear(); // no change because t2 is already empty and t1 is independent With tables, memory is explicitly transferred on instantiation so the buffers held by a table are held by only that table. Creating Tables with dictionary-encoded vectors¶Another point of difference is that VectorSchemaRoot vsr = myVsr(); DictionaryProvider provider = myProvider(); Table t = new Table(vsr, provider); In Table t = new Table(vsr, provider); ValueVector decodedName = t.decode("name", 1L); To encode a vector from a table, a similar approach is used: Table t = new Table(vsr, provider); ValueVector encodedName = t.encode("name", 1L); Freeing memory explicitly¶Tables use off-heap memory that must be freed when it is no longer needed. try (VectorSchemaRoot vsr = myMethodForGettingVsrs(); Table t = new Table(vsr)) { // do useful things. } If you don’t use a try-with-resources block, you must close the table manually: try { VectorSchemaRoot vsr = myMethodForGettingVsrs(); Table t = new Table(vsr); // do useful things. } finally { vsr.close(); t.close(); } Manual closing should be performed in a finally block. Getting the schema¶You get the table’s schema just as you would with a vector schema root: Schema s = table.getSchema(); Adding and removing vectors¶
try (Table t = new Table(vectorList)) { IntVector v3 = new IntVector("3", intFieldType, allocator); Table t2 = t.addVector(2, v3); Table t3 = t2.removeVector(1); // don't forget to close t2 and t3 } Slicing tables¶
try (Table t = new Table(vectorList)) { Table t2 = t.slice(100, 200); // creates a slice referencing the values in range (100, 200] ... } This raises the question: If you create a slice with all the values in the source table (as shown below), how would that differ from a new Table constructed with the same vectors as the source? try (Table t = new Table(vectorList)) { Table t2 = t.slice(0, t.getRowCount()); // creates a slice referencing all the values in t // ... } The difference is that when you construct a new table, the buffers are transferred from the source vectors to new vectors in the destination. With a slice, both tables share the same underlying vectors. That’s OK, though, since both tables are immutable. Using FieldReaders¶You can get a FieldReader for any vector in the Table passing either the Field, vector index, or vector name as an argument. The signatures are the same as in FieldReader nameReader = table.getReader("user_name"); Row operations¶Row-based access is supported by the Row object. It is important to recognize that rows are NOT reified as objects, but rather operate like a cursor where the data from numerous logical rows in the table can be viewed (one at a time) using the same Getting a row¶Calling Row r = table.immutableRow(); Moving from row-to-row¶Since rows are iterable, you can traverse a table using a standard while loop: Row r = table.immutableRow(); while (r.hasNext()) { r.next(); // do something useful here }
for (Row row: table) { int age = row.getInt("age"); boolean nameIsNull = row.isNull("name"); ... } Finally, while rows are usually iterated in the order of the underlying data vectors, but they are also positionable using the Row r = table.immutableRow(); int age101 = r.setPosition(101); // change position directly to 101 Any changes to position are applied to all the columns in the table. Note that you must call Read operations using rows¶Methods are available for getting values by vector name and vector index, where index is the 0-based position of the vector in the table. For example, assuming ‘age’ is the 13th vector in ‘table’, the following two gets are equivalent: Row r = table.immutableRow(); r.next(); // position the row at the first value int age1 = r.get("age"); // gets the value of vector named 'age' in the table at row 0 int age2 = r.get(12); // gets the value of the 13th vector in the table at row 0 You can also get value using a nullable NullableIntHolder holder = new NullableIntHolder(); int b = row.getInt("age", holder); This can be used to retrieve values without creating a new Object for each. In addition to getting values, you can check if a value is null using boolean name0isNull = row.isNull("name"); You can also get the current row number: int row = row.getRowNumber(); Reading values as Objects¶For any given vector type, the basic get() method returns a primitive value wherever possible. For example, getTimeStampMicro() returns a long value that encodes the timestamp. To get the LocalDateTime object representing that timestamp in Java, another method with ‘Obj’ appended to the name is provided. For example: long ts = row.getTimeStampMicro(); LocalDateTime tsObject = row.getTimeStampMicroObj(); The exception to this naming scheme is for complex vector types (List, Map, Schema, Union, DenseUnion, and ExtensionType). These always return objects rather than primitives so no “Obj” extension is required. It is expected that some users may subclass Reading VarChars and LargeVarChars¶Strings in arrow are represented as byte arrays encoded with the UTF-8 charset. You can get either a String result or the actual byte array. byte[] b = row.getVarChar("first_name"); String s = row.getVarCharObj("first_name"); // uses the default encoding (UTF-8) Converting a Table to a VectorSchemaRoot¶Tables can be converted to vector schema roots using the toVectorSchemaRoot() method. Buffers are transferred to the vector schema root and the source table is cleared. VectorSchemaRoot root = myTable.toVectorSchemaRoot(); Working with the C-Data interface¶The ability to work with native code is required for many Arrow features. This section describes how tables can be be exported for use with native code Exporting works by converting the data to a Data.exportTable(bufferAllocator, table, dictionaryProvider, outArrowArray); If the table contains dictionary-encoded vectors and was constructed with a Data.exportTable(bufferAllocator, table, outArrowArray); |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |