blob: d389db09392b18ba0f3ce558bd6dcd28a27e9450 [file] [log] [blame]
<!doctype html>
<html class="no-js" lang="en" data-content_root="./">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Reading/Writing IPC formats" href="ipc.html" /><link rel="prev" title="Tabular Data" href="vector_schema_root.html" />
<!-- Generated with Sphinx 8.1.3 and Furo 2024.08.06 -->
<title>Table - arrow-java 18.1.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=8f2a1f02" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=354aac6f" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=302659d7" />
<style>
body {
--color-code-background: #f8f8f8;
--color-code-foreground: black;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<script>
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
</script>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-with-moon" viewBox="0 0 24 24">
<title>Auto light/dark, in light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="icon-custom-derived-from-feather-sun-and-tabler-moon">
<path style="opacity: 50%" d="M 5.411 14.504 C 5.471 14.504 5.532 14.504 5.591 14.504 C 3.639 16.319 4.383 19.569 6.931 20.352 C 7.693 20.586 8.512 20.551 9.25 20.252 C 8.023 23.207 4.056 23.725 2.11 21.184 C 0.166 18.642 1.702 14.949 4.874 14.536 C 5.051 14.512 5.231 14.5 5.411 14.5 L 5.411 14.504 Z"/>
<line x1="14.5" y1="3.25" x2="14.5" y2="1.25"/>
<line x1="14.5" y1="15.85" x2="14.5" y2="17.85"/>
<line x1="10.044" y1="5.094" x2="8.63" y2="3.68"/>
<line x1="19" y1="14.05" x2="20.414" y2="15.464"/>
<line x1="8.2" y1="9.55" x2="6.2" y2="9.55"/>
<line x1="20.8" y1="9.55" x2="22.8" y2="9.55"/>
<line x1="10.044" y1="14.006" x2="8.63" y2="15.42"/>
<line x1="19" y1="5.05" x2="20.414" y2="3.636"/>
<circle cx="14.5" cy="9.55" r="3.6"/>
</svg>
</symbol>
<symbol id="svg-moon-with-sun" viewBox="0 0 24 24">
<title>Auto light/dark, in dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="icon-custom-derived-from-feather-sun-and-tabler-moon">
<path d="M 8.282 7.007 C 8.385 7.007 8.494 7.007 8.595 7.007 C 5.18 10.184 6.481 15.869 10.942 17.24 C 12.275 17.648 13.706 17.589 15 17.066 C 12.851 22.236 5.91 23.143 2.505 18.696 C -0.897 14.249 1.791 7.786 7.342 7.063 C 7.652 7.021 7.965 7 8.282 7 L 8.282 7.007 Z"/>
<line style="opacity: 50%" x1="18" y1="3.705" x2="18" y2="2.5"/>
<line style="opacity: 50%" x1="18" y1="11.295" x2="18" y2="12.5"/>
<line style="opacity: 50%" x1="15.316" y1="4.816" x2="14.464" y2="3.964"/>
<line style="opacity: 50%" x1="20.711" y1="10.212" x2="21.563" y2="11.063"/>
<line style="opacity: 50%" x1="14.205" y1="7.5" x2="13.001" y2="7.5"/>
<line style="opacity: 50%" x1="21.795" y1="7.5" x2="23" y2="7.5"/>
<line style="opacity: 50%" x1="15.316" y1="10.184" x2="14.464" y2="11.036"/>
<line style="opacity: 50%" x1="20.711" y1="4.789" x2="21.563" y2="3.937"/>
<circle style="opacity: 50%" cx="18" cy="7.5" r="2.169"/>
</svg>
</symbol>
<symbol id="svg-pencil" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-pencil-code">
<path d="M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4" />
<path d="M13.5 6.5l4 4" />
<path d="M20 21l2 -2l-2 -2" />
<path d="M17 17l-2 2l2 2" />
</svg>
</symbol>
<symbol id="svg-eye" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-eye-code">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path
d="M11.11 17.958c-3.209 -.307 -5.91 -2.293 -8.11 -5.958c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6c-.21 .352 -.427 .688 -.647 1.008" />
<path d="M20 21l2 -2l-2 -2" />
<path d="M17 17l-2 2l2 2" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
<div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
<div class="visually-hidden">Hide table of contents sidebar</div>
</label>
<a class="skip-to-content muted-link" href="#furo-main-content">Skip to content</a>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<div class="visually-hidden">Toggle site navigation sidebar</div>
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">arrow-java 18.1.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">arrow-java 18.1.0 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="quickstartguide.html">Quick Start Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="overview.html">High-Level Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installing Java Modules</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="developers/index.html">Java Development</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Java Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="developers/building.html">Building Arrow Java</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers/development.html">Development Guidelines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="memory.html">Memory Management</a></li>
<li class="toctree-l1"><a class="reference internal" href="vector.html">ValueVector</a></li>
<li class="toctree-l1"><a class="reference internal" href="vector_schema_root.html">Tabular Data</a></li>
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Table</a></li>
<li class="toctree-l1"><a class="reference internal" href="ipc.html">Reading/Writing IPC formats</a></li>
<li class="toctree-l1"><a class="reference internal" href="algorithm.html">Java Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="flight.html">Arrow Flight RPC</a></li>
<li class="toctree-l1"><a class="reference internal" href="flight_sql.html">Arrow Flight SQL</a></li>
<li class="toctree-l1"><a class="reference internal" href="flight_sql_jdbc_driver.html">Arrow Flight SQL JDBC Driver</a></li>
<li class="toctree-l1"><a class="reference internal" href="dataset.html">Dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="substrait.html">Substrait</a></li>
<li class="toctree-l1"><a class="reference internal" href="cdata.html">C Data Interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="jdbc.html">Arrow JDBC Adapter</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference (javadoc)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/cookbook/java/">Cookbook</a></li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<div class="main">
<div class="content">
<div class="article-container">
<a href="#" class="back-to-top muted-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
</svg>
<span>Back to top</span>
</a>
<div class="content-icon-container">
<div class="view-this-page">
<a class="muted-link" href="_sources/table.rst.txt" title="View this page">
<svg><use href="#svg-eye"></use></svg>
<span class="visually-hidden">View this page</span>
</a>
</div>
<div class="theme-toggle-container theme-toggle-content">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
<article role="main" id="furo-main-content">
<section id="table">
<h1>Table<a class="headerlink" href="#table" title="Link to this heading"></a></h1>
<p><strong>NOTE</strong>: The Table API is experimental and subject to change. See the list of limitations below.</p>
<p><a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/table/Table.html">Table</a> is an immutable tabular data structure based on <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/FieldVector.html">FieldVector</a>. Like <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/VectorSchemaRoot.html">VectorSchemaRoot</a>, <code class="docutils literal notranslate"><span class="pre">Table</span></code> is a columnar data structure backed by Arrow arrays, or more specifically, by <code class="docutils literal notranslate"><span class="pre">FieldVector</span></code> objects. It differs from <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> mainly in that it is fully immutable and lacks support for batch operations. Anyone processing batches of tabular data in a pipeline should continue to use <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>. Finally, the <code class="docutils literal notranslate"><span class="pre">Table</span></code> API is mainly row-oriented, so in some ways it’s more like the JDBC API than the <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> API, but you can still use <code class="docutils literal notranslate"><span class="pre">FieldReaders</span></code> to work with data in a columnar fashion.</p>
<section id="mutation-in-table-and-vectorschemaroot">
<h2>Mutation in Table and VectorSchemaRoot<a class="headerlink" href="#mutation-in-table-and-vectorschemaroot" title="Link to this heading"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> provides a thin wrapper on the vectors that hold its data. Individual vectors can be retrieved from a vector schema root. These vectors have <em>setters</em> for modifying their elements, making <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> immutable only by convention. The protocol for mutating a vector is documented in the <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/ValueVector.html">ValueVector</a> interface:</p>
<ul class="simple">
<li><p>values need to be written in order (e.g. index 0, 1, 2, 5)</p></li>
<li><p>null vectors start with all values as null before writing anything</p></li>
<li><p>for variable width types, the offset vector should be all zeros before writing</p></li>
<li><p>you must call setValueCount before a vector can be read</p></li>
<li><p>you should never write to a vector once it has been read.</p></li>
</ul>
<p>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.</p>
<p><code class="docutils literal notranslate"><span class="pre">Table</span></code>, on the other hand, is immutable. The underlying vectors are not exposed. When a table is created from existing vectors, their memory is transferred to new vectors, so subsequent changes to the original vectors can’t impact the new table’s values.</p>
</section>
<section id="features-and-limitations">
<h2>Features and limitations<a class="headerlink" href="#features-and-limitations" title="Link to this heading"></a></h2>
<p>A basic set of table functionality is currently available:</p>
<ul class="simple">
<li><p>Create a table from vectors or <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code></p></li>
<li><p>Iterate tables by row, or set the current row index directly</p></li>
<li><p>Access vector values as primitives, objects, and/or nullable <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/holders/ValueHolder.html">ValueHolder</a> instances (depending on type)</p></li>
<li><p>Get a <code class="docutils literal notranslate"><span class="pre">FieldReader</span></code> for any vector</p></li>
<li><p>Add and remove vectors, creating new tables</p></li>
<li><p>Encode and decode a table’s vectors using dictionary encoding</p></li>
<li><p>Export table data for use by native code</p></li>
<li><p>Print representative data to TSV strings</p></li>
<li><p>Get a table’s schema</p></li>
<li><p>Slice tables</p></li>
<li><p>Convert table to <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code></p></li>
</ul>
<p>Limitations in the 11.0.0 release:</p>
<ul class="simple">
<li><p>No support <code class="docutils literal notranslate"><span class="pre">ChunkedArray</span></code> or any form of row-group. Support for chunked arrays or row groups will be considered for a future release.</p></li>
<li><p>No support for the C-Stream API. Support for the streaming API is contingent on chunked array support</p></li>
<li><p>No support for creating tables directly from Java POJOs. All data held by a table must be imported via a <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>, or from collections or arrays of vectors.</p></li>
</ul>
</section>
<section id="the-table-api">
<h2>The Table API<a class="headerlink" href="#the-table-api" title="Link to this heading"></a></h2>
<p>Like <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>, a table contains a <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/types/pojo/Schema.html">Schema</a> and an ordered collection of <code class="docutils literal notranslate"><span class="pre">FieldVector</span></code> objects, but it is designed to be accessed via a row-oriented interface.</p>
<section id="creating-a-table-from-a-vectorschemaroot">
<h3>Creating a Table from a VectorSchemaRoot<a class="headerlink" href="#creating-a-table-from-a-vectorschemaroot" title="Link to this heading"></a></h3>
<p>Tables are created from a <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> as shown below. The memory buffers holding the data are transferred from the vector schema root to new vectors in the new table, clearing the source vectors in the process. This ensures that the data in your new table is never changed. Since the buffers are transferred rather than copied, this is a very low overhead operation.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">someVectorSchemaRoot</span><span class="p">);</span>
</pre></div>
</div>
<p>If you now update the vectors held by the <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> (using some version of <code class="docutils literal notranslate"><span class="pre">ValueVector#setSafe()</span></code>), it would reflect those changes, but the values in table <em>t</em> are unchanged.</p>
</section>
<section id="creating-a-table-from-fieldvectors">
<h3>Creating a Table from FieldVectors<a class="headerlink" href="#creating-a-table-from-fieldvectors" title="Link to this heading"></a></h3>
<p>Tables can be created from <code class="docutils literal notranslate"><span class="pre">FieldVectors</span></code> as shown below, using ‘var-arg’ array arguments:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">IntVector</span><span class="w"> </span><span class="n">myVector</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">createMyIntVector</span><span class="p">();</span>
<span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">VectorSchemaRoot</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span>
</pre></div>
</div>
<p>or by passing a collection:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">IntVector</span><span class="w"> </span><span class="n">myVector</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">createMyIntVector</span><span class="p">();</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">FieldVector</span><span class="o">&gt;</span><span class="w"> </span><span class="n">fvList</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">List</span><span class="p">.</span><span class="na">of</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span>
<span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">VectorSchemaRoot</span><span class="p">(</span><span class="n">fvList</span><span class="p">);</span>
</pre></div>
</div>
<p>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 <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> from a list of vectors does not cause the reference counts for the vectors to be incremented. Unless you manage the counts manually, the code below would lead to more references than reference counts, and that could lead to trouble. There is an implicit assumption that the vectors were created for use by <em>one</em> <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> that this code violates.</p>
<p><em>Don’t do this:</em></p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">IntVector</span><span class="w"> </span><span class="n">myVector</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">createMyIntVector</span><span class="p">();</span><span class="w"> </span><span class="c1">// Reference count for myVector = 1</span>
<span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">VectorSchemaRoot</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span><span class="w"> </span><span class="c1">// Still one reference</span>
<span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">VectorSchemaRoot</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span>
<span class="c1">// Ref count is still one, but there are two VSRs with a reference to myVector</span>
<span class="n">vsr2</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span><span class="w"> </span><span class="c1">// Reference count for myVector is 0.</span>
</pre></div>
</div>
<p>What is happening is that the reference counter works at a lower level than the <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> interface. A reference counter counts references to <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/memory/ArrowBuf.html">ArrowBuf</a> instances that control memory buffers. It doesn’t count references to the vectors that hold those ArrowBufs. In the example above, each <code class="docutils literal notranslate"><span class="pre">ArrowBuf</span></code> is held by one vector, so there is only one reference. This distinction is blurred when you call the <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>’s clear() method, which frees the memory held by each of the vectors it references even though another instance references the same vectors.</p>
<p>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.</p>
<p><em>Don’t do this either, but note the difference from above:</em></p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">IntVector</span><span class="w"> </span><span class="n">myVector</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">createMyIntVector</span><span class="p">();</span><span class="w"> </span><span class="c1">// Reference count for myVector = 1</span>
<span class="n">Table</span><span class="w"> </span><span class="n">t1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span>
<span class="c1">// myVector is cleared; Table t1 has a new hidden vector with the data from myVector</span>
<span class="n">Table</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">myVector</span><span class="p">);</span>
<span class="c1">// t2 has no rows because myVector was just cleared</span>
<span class="c1">// t1 continues to have the data from the original vector</span>
<span class="n">t2</span><span class="p">.</span><span class="na">clear</span><span class="p">();</span>
<span class="c1">// no change because t2 is already empty and t1 is independent</span>
</pre></div>
</div>
<p>With tables, memory is explicitly transferred on instantiation so the buffers held by a table are held by <em>only</em> that table.</p>
</section>
<section id="creating-tables-with-dictionary-encoded-vectors">
<h3>Creating Tables with dictionary-encoded vectors<a class="headerlink" href="#creating-tables-with-dictionary-encoded-vectors" title="Link to this heading"></a></h3>
<p>Another point of difference is that <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> is uninformed about any dictionary-encoding of its vectors, while tables hold an optional <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/dictionary/DictionaryProvider.html">DictionaryProvider</a> instance. If any vectors in the source data are encoded, a DictionaryProvider must be set to un-encode the values.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myVsr</span><span class="p">();</span>
<span class="n">DictionaryProvider</span><span class="w"> </span><span class="n">provider</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myProvider</span><span class="p">();</span>
<span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vsr</span><span class="p">,</span><span class="w"> </span><span class="n">provider</span><span class="p">);</span>
</pre></div>
</div>
<p>In <code class="docutils literal notranslate"><span class="pre">Table</span></code>, dictionaries are used like they are with vectors. To decode a vector, the user provides the name of the vector to decode and the dictionary id:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vsr</span><span class="p">,</span><span class="w"> </span><span class="n">provider</span><span class="p">);</span>
<span class="n">ValueVector</span><span class="w"> </span><span class="n">decodedName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">decode</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1L</span><span class="p">);</span>
</pre></div>
</div>
<p>To encode a vector from a table, a similar approach is used:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vsr</span><span class="p">,</span><span class="w"> </span><span class="n">provider</span><span class="p">);</span>
<span class="n">ValueVector</span><span class="w"> </span><span class="n">encodedName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">encode</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">1L</span><span class="p">);</span>
</pre></div>
</div>
</section>
<section id="freeing-memory-explicitly">
<h3>Freeing memory explicitly<a class="headerlink" href="#freeing-memory-explicitly" title="Link to this heading"></a></h3>
<p>Tables use off-heap memory that must be freed when it is no longer needed. <code class="docutils literal notranslate"><span class="pre">Table</span></code> implements <code class="docutils literal notranslate"><span class="pre">AutoCloseable</span></code> so the best way to create one is in a try-with-resources block:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myMethodForGettingVsrs</span><span class="p">();</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vsr</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// do useful things.</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If you don’t use a try-with-resources block, you must close the table manually:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">vsr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myMethodForGettingVsrs</span><span class="p">();</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vsr</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// do useful things.</span>
<span class="p">}</span><span class="w"> </span><span class="k">finally</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">vsr</span><span class="p">.</span><span class="na">close</span><span class="p">();</span>
<span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">close</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Manual closing should be performed in a finally block.</p>
</section>
<section id="getting-the-schema">
<h3>Getting the schema<a class="headerlink" href="#getting-the-schema" title="Link to this heading"></a></h3>
<p>You get the table’s schema just as you would with a vector schema root:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Schema</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">getSchema</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="adding-and-removing-vectors">
<h3>Adding and removing vectors<a class="headerlink" href="#adding-and-removing-vectors" title="Link to this heading"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">Table</span></code> provides facilities for adding and removing vectors modeled on the same functionality in <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>. These operations return new instances rather than modifying the original instance in-place.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vectorList</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">IntVector</span><span class="w"> </span><span class="n">v3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IntVector</span><span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">intFieldType</span><span class="p">,</span><span class="w"> </span><span class="n">allocator</span><span class="p">);</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">addVector</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">v3</span><span class="p">);</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t2</span><span class="p">.</span><span class="na">removeVector</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// don&#39;t forget to close t2 and t3</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
<section id="slicing-tables">
<h3>Slicing tables<a class="headerlink" href="#slicing-tables" title="Link to this heading"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">Table</span></code> supports <em>slice()</em> operations, where a slice of a source table is a second Table that refers to a single, contiguous range of rows in the source.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vectorList</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">slice</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="mi">200</span><span class="p">);</span><span class="w"> </span><span class="c1">// creates a slice referencing the values in range (100, 200]</span>
<span class="w"> </span><span class="p">...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This raises the question: If you create a slice with <em>all</em> 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?</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">Table</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Table</span><span class="p">(</span><span class="n">vectorList</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Table</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">.</span><span class="na">getRowCount</span><span class="p">());</span><span class="w"> </span><span class="c1">// creates a slice referencing all the values in t</span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The difference is that when you <em>construct</em> 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.</p>
</section>
<section id="using-fieldreaders">
<h3>Using FieldReaders<a class="headerlink" href="#using-fieldreaders" title="Link to this heading"></a></h3>
<p>You can get a <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/complex/reader/FieldReader.html">FieldReader</a> for any vector in the Table passing either the <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/types/pojo/Field.html">Field</a>, vector index, or vector name as an argument. The signatures are the same as in <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code>.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">FieldReader</span><span class="w"> </span><span class="n">nameReader</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">getReader</span><span class="p">(</span><span class="s">&quot;user_name&quot;</span><span class="p">);</span>
</pre></div>
</div>
</section>
<section id="row-operations">
<h3>Row operations<a class="headerlink" href="#row-operations" title="Link to this heading"></a></h3>
<p>Row-based access is supported by the <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/vector/table/Row.html">Row</a> object. <code class="docutils literal notranslate"><span class="pre">Row</span></code> provides <em>get()</em> methods by both vector name and vector position, but no <em>set()</em> operations.</p>
<p>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 <code class="docutils literal notranslate"><span class="pre">Row</span></code> instance. See “Moving from row-to-row” below for information about navigating through the table.</p>
</section>
<section id="getting-a-row">
<h3>Getting a row<a class="headerlink" href="#getting-a-row" title="Link to this heading"></a></h3>
<p>Calling <code class="docutils literal notranslate"><span class="pre">immutableRow()</span></code> on any table instance returns a new <code class="docutils literal notranslate"><span class="pre">Row</span></code> instance.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Row</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">immutableRow</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="moving-from-row-to-row">
<h3>Moving from row-to-row<a class="headerlink" href="#moving-from-row-to-row" title="Link to this heading"></a></h3>
<p>Since rows are iterable, you can traverse a table using a standard while loop:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Row</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">immutableRow</span><span class="p">();</span>
<span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">r</span><span class="p">.</span><span class="na">hasNext</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">r</span><span class="p">.</span><span class="na">next</span><span class="p">();</span>
<span class="w"> </span><span class="c1">// do something useful here</span>
<span class="p">}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Table</span></code> implements <code class="docutils literal notranslate"><span class="pre">Iterable&lt;Row&gt;</span></code> so you can access rows directly from a table in an enhanced <em>for</em> loop:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="n">Row</span><span class="w"> </span><span class="n">row</span><span class="p">:</span><span class="w"> </span><span class="n">table</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">age</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getInt</span><span class="p">(</span><span class="s">&quot;age&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="n">nameIsNull</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">isNull</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="p">...</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Finally, while rows are usually iterated in the order of the underlying data vectors, but they are also positionable using the <code class="docutils literal notranslate"><span class="pre">Row#setPosition()</span></code> method, so you can skip to a specific row. Row numbers are 0-based.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Row</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">immutableRow</span><span class="p">();</span>
<span class="kt">int</span><span class="w"> </span><span class="n">age101</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="p">.</span><span class="na">setPosition</span><span class="p">(</span><span class="mi">101</span><span class="p">);</span><span class="w"> </span><span class="c1">// change position directly to 101</span>
</pre></div>
</div>
<p>Any changes to position are applied to all the columns in the table.</p>
<p>Note that you must call <code class="docutils literal notranslate"><span class="pre">next()</span></code>, or <code class="docutils literal notranslate"><span class="pre">setPosition()</span></code> before accessing values via a row. Failure to do so results in a runtime exception.</p>
</section>
<section id="read-operations-using-rows">
<h3>Read operations using rows<a class="headerlink" href="#read-operations-using-rows" title="Link to this heading"></a></h3>
<p>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:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Row</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table</span><span class="p">.</span><span class="na">immutableRow</span><span class="p">();</span>
<span class="n">r</span><span class="p">.</span><span class="na">next</span><span class="p">();</span><span class="w"> </span><span class="c1">// position the row at the first value</span>
<span class="kt">int</span><span class="w"> </span><span class="n">age1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="s">&quot;age&quot;</span><span class="p">);</span><span class="w"> </span><span class="c1">// gets the value of vector named &#39;age&#39; in the table at row 0</span>
<span class="kt">int</span><span class="w"> </span><span class="n">age2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="mi">12</span><span class="p">);</span><span class="w"> </span><span class="c1">// gets the value of the 13th vector in the table at row 0</span>
</pre></div>
</div>
<p>You can also get value using a nullable <code class="docutils literal notranslate"><span class="pre">ValueHolder</span></code>. For example:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">NullableIntHolder</span><span class="w"> </span><span class="n">holder</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">NullableIntHolder</span><span class="p">();</span>
<span class="kt">int</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getInt</span><span class="p">(</span><span class="s">&quot;age&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">holder</span><span class="p">);</span>
</pre></div>
</div>
<p>This can be used to retrieve values without creating a new Object for each.</p>
<p>In addition to getting values, you can check if a value is null using <code class="docutils literal notranslate"><span class="pre">isNull()</span></code>. This is important if the vector contains any nulls, as asking for a value from a vector can cause NullPointerExceptions in some cases.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">boolean</span><span class="w"> </span><span class="n">name0isNull</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">isNull</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>You can also get the current row number:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">row</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getRowNumber</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="reading-values-as-objects">
<h3>Reading values as Objects<a class="headerlink" href="#reading-values-as-objects" title="Link to this heading"></a></h3>
<p>For any given vector type, the basic <em>get()</em> method returns a primitive value wherever possible. For example, <em>getTimeStampMicro()</em> 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:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">long</span><span class="w"> </span><span class="n">ts</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getTimeStampMicro</span><span class="p">();</span>
<span class="n">LocalDateTime</span><span class="w"> </span><span class="n">tsObject</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getTimeStampMicroObj</span><span class="p">();</span>
</pre></div>
</div>
<p>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 <code class="docutils literal notranslate"><span class="pre">Row</span></code> to add getters that are more specific to their needs.</p>
</section>
<section id="reading-varchars-and-largevarchars">
<h3>Reading VarChars and LargeVarChars<a class="headerlink" href="#reading-varchars-and-largevarchars" title="Link to this heading"></a></h3>
<p>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.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span><span class="o">[]</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getVarChar</span><span class="p">(</span><span class="s">&quot;first_name&quot;</span><span class="p">);</span>
<span class="n">String</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">row</span><span class="p">.</span><span class="na">getVarCharObj</span><span class="p">(</span><span class="s">&quot;first_name&quot;</span><span class="p">);</span><span class="w"> </span><span class="c1">// uses the default encoding (UTF-8)</span>
</pre></div>
</div>
</section>
<section id="converting-a-table-to-a-vectorschemaroot">
<h3>Converting a Table to a VectorSchemaRoot<a class="headerlink" href="#converting-a-table-to-a-vectorschemaroot" title="Link to this heading"></a></h3>
<p>Tables can be converted to vector schema roots using the <em>toVectorSchemaRoot()</em> method. Buffers are transferred to the vector schema root and the source table is cleared.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">VectorSchemaRoot</span><span class="w"> </span><span class="n">root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myTable</span><span class="p">.</span><span class="na">toVectorSchemaRoot</span><span class="p">();</span>
</pre></div>
</div>
</section>
<section id="working-with-the-c-data-interface">
<h3>Working with the C-Data interface<a class="headerlink" href="#working-with-the-c-data-interface" title="Link to this heading"></a></h3>
<p>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</p>
<p>Exporting works by converting the data to a <code class="docutils literal notranslate"><span class="pre">VectorSchemaRoot</span></code> instance and using the existing facilities to transfer the data. You could do it yourself, but that isn’t ideal because conversion to a vector schema root breaks the immutability guarantees. Using the <code class="docutils literal notranslate"><span class="pre">exportTable()</span></code> methods in the <a class="reference external" href="https://arrow.apache.org/docs/java/reference/org/apache/arrow/c/Data.html">Data</a> class avoids this concern.</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Data</span><span class="p">.</span><span class="na">exportTable</span><span class="p">(</span><span class="n">bufferAllocator</span><span class="p">,</span><span class="w"> </span><span class="n">table</span><span class="p">,</span><span class="w"> </span><span class="n">dictionaryProvider</span><span class="p">,</span><span class="w"> </span><span class="n">outArrowArray</span><span class="p">);</span>
</pre></div>
</div>
<p>If the table contains dictionary-encoded vectors and was constructed with a <code class="docutils literal notranslate"><span class="pre">DictionaryProvider</span></code>, the provider argument to <code class="docutils literal notranslate"><span class="pre">exportTable()</span></code> can be omitted and the table’s provider attribute will be used:</p>
<div class="highlight-Java notranslate"><div class="highlight"><pre><span></span><span class="n">Data</span><span class="p">.</span><span class="na">exportTable</span><span class="p">(</span><span class="n">bufferAllocator</span><span class="p">,</span><span class="w"> </span><span class="n">table</span><span class="p">,</span><span class="w"> </span><span class="n">outArrowArray</span><span class="p">);</span>
</pre></div>
</div>
</section>
</section>
</section>
</article>
</div>
<footer>
<div class="related-pages">
<a class="next-page" href="ipc.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Reading/Writing IPC formats</div>
</div>
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
</a>
<a class="prev-page" href="vector_schema_root.html">
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
<div class="page-info">
<div class="context">
<span>Previous</span>
</div>
<div class="title">Tabular Data</div>
</div>
</a>
</div>
<div class="bottom-of-page">
<div class="left-details">
<div class="copyright">
Copyright &#169; 2025, Apache Arrow Developers
</div>
Made with <a href="https://www.sphinx-doc.org/">Sphinx</a> and <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
<a href="https://github.com/pradyunsg/furo">Furo</a>
</div>
<div class="right-details">
</div>
</div>
</footer>
</div>
<aside class="toc-drawer">
<div class="toc-sticky toc-scroll">
<div class="toc-title-container">
<span class="toc-title">
On this page
</span>
</div>
<div class="toc-tree-container">
<div class="toc-tree">
<ul>
<li><a class="reference internal" href="#">Table</a><ul>
<li><a class="reference internal" href="#mutation-in-table-and-vectorschemaroot">Mutation in Table and VectorSchemaRoot</a></li>
<li><a class="reference internal" href="#features-and-limitations">Features and limitations</a></li>
<li><a class="reference internal" href="#the-table-api">The Table API</a><ul>
<li><a class="reference internal" href="#creating-a-table-from-a-vectorschemaroot">Creating a Table from a VectorSchemaRoot</a></li>
<li><a class="reference internal" href="#creating-a-table-from-fieldvectors">Creating a Table from FieldVectors</a></li>
<li><a class="reference internal" href="#creating-tables-with-dictionary-encoded-vectors">Creating Tables with dictionary-encoded vectors</a></li>
<li><a class="reference internal" href="#freeing-memory-explicitly">Freeing memory explicitly</a></li>
<li><a class="reference internal" href="#getting-the-schema">Getting the schema</a></li>
<li><a class="reference internal" href="#adding-and-removing-vectors">Adding and removing vectors</a></li>
<li><a class="reference internal" href="#slicing-tables">Slicing tables</a></li>
<li><a class="reference internal" href="#using-fieldreaders">Using FieldReaders</a></li>
<li><a class="reference internal" href="#row-operations">Row operations</a></li>
<li><a class="reference internal" href="#getting-a-row">Getting a row</a></li>
<li><a class="reference internal" href="#moving-from-row-to-row">Moving from row-to-row</a></li>
<li><a class="reference internal" href="#read-operations-using-rows">Read operations using rows</a></li>
<li><a class="reference internal" href="#reading-values-as-objects">Reading values as Objects</a></li>
<li><a class="reference internal" href="#reading-varchars-and-largevarchars">Reading VarChars and LargeVarChars</a></li>
<li><a class="reference internal" href="#converting-a-table-to-a-vectorschemaroot">Converting a Table to a VectorSchemaRoot</a></li>
<li><a class="reference internal" href="#working-with-the-c-data-interface">Working with the C-Data interface</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</aside>
</div>
</div><script src="_static/documentation_options.js?v=c4c92189"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=5fa4622c"></script>
</body>
</html>