1. Structure
  2. Life Sciences
  3. Single-cell
  4. Foundation
  5. Key Concepts
  6. Use of Apache Arrow
  • Home
  • What is TileDB?
  • Get Started
  • Explore Content
  • Accounts
    • Individual Accounts
      • Apply for the Free Tier
      • Profile
        • Overview
        • Cloud Credentials
        • Storage Paths
        • REST API Tokens
        • Credits
    • Organization Admins
      • Create an Organization
      • Profile
        • Overview
        • Members
        • Cloud Credentials
        • Storage Paths
        • Billing
      • API Tokens
    • Organization Members
      • Organization Invitations
      • Profile
        • Overview
        • Members
        • Cloud Credentials
        • Storage Paths
        • Billing
      • API Tokens
  • Catalog
    • Introduction
    • Data
      • Arrays
      • Tables
      • Single-Cell (SOMA)
      • Genomics (VCF)
      • Biomedical Imaging
      • Vector Search
      • Files
    • Code
      • Notebooks
      • Dashboards
      • User-Defined Functions
      • Task Graphs
      • ML Models
    • Groups
    • Marketplace
    • Search
  • Collaborate
    • Introduction
    • Organizations
    • Access Control
      • Introduction
      • Share Assets
      • Asset Permissions
      • Public Assets
    • Logging
    • Marketplace
  • Analyze
    • Introduction
    • Slice Data
    • Multi-Region Redirection
    • Notebooks
      • Launch a Notebook
      • Usage
      • Widgets
      • Notebook Image Dependencies
    • Dashboards
      • Dashboards
      • Streamlit
    • Preview
    • User-Defined Functions
    • Task Graphs
    • Serverless SQL
    • Monitor
      • Task Log
      • Task Graph Log
  • Scale
    • Introduction
    • Task Graphs
    • API Usage
  • Structure
    • Why Structure Is Important
    • Arrays
      • Introduction
      • Quickstart
      • Foundation
        • Array Data Model
        • Key Concepts
          • Storage
            • Arrays
            • Dimensions
            • Attributes
            • Cells
            • Domain
            • Tiles
            • Data Layout
            • Compression
            • Encryption
            • Tile Filters
            • Array Schema
            • Schema Evolution
            • Fragments
            • Fragment Metadata
            • Commits
            • Indexing
            • Array Metadata
            • Datetimes
            • Groups
            • Object Stores
          • Compute
            • Writes
            • Deletions
            • Consolidation
            • Vacuuming
            • Time Traveling
            • Reads
            • Query Conditions
            • Aggregates
            • User-Defined Functions
            • Distributed Compute
            • Concurrency
            • Parallelism
        • Storage Format Spec
      • Tutorials
        • Basics
          • Basic Dense Array
          • Basic Sparse Array
          • Array Metadata
          • Compression
          • Encryption
          • Data Layout
          • Tile Filters
          • Datetimes
          • Multiple Attributes
          • Variable-Length Attributes
          • String Dimensions
          • Nullable Attributes
          • Multi-Range Reads
          • Query Conditions
          • Aggregates
          • Deletions
          • Catching Errors
          • Configuration
          • Basic S3 Example
          • Basic TileDB Cloud
          • fromDataFrame
          • Palmer Penguins
        • Advanced
          • Schema Evolution
          • Advanced Writes
            • Write at a Timestamp
            • Get Fragment Info
            • Consolidation
              • Fragments
              • Fragment List
              • Consolidation Plan
              • Commits
              • Fragment Metadata
              • Array Metadata
            • Vacuuming
              • Fragments
              • Commits
              • Fragment Metadata
              • Array Metadata
          • Advanced Reads
            • Get Fragment Info
            • Time Traveling
              • Introduction
              • Fragments
              • Array Metadata
              • Schema Evolution
          • Array Upgrade
          • Backends
            • Amazon S3
            • Azure Blob Storage
            • Google Cloud Storage
            • MinIO
            • Lustre
          • Virtual Filesystem
          • User-Defined Functions
          • Distributed Compute
          • Result Estimation
          • Incomplete Queries
        • Management
          • Array Schema
          • Groups
          • Object Management
        • Performance
          • Summary of Factors
          • Dense vs. Sparse
          • Dimensions vs. Attributes
          • Compression
          • Tiling and Data Layout
          • Tuning Writes
          • Tuning Reads
      • API Reference
    • Tables
      • Introduction
      • Quickstart
      • Foundation
        • Data Model
        • Key Concepts
          • Indexes
          • Columnar Storage
          • Compression
          • Data Manipulation
          • Optimize Tables
          • ACID
          • Serverless SQL
          • SQL Connectors
          • Dataframes
          • CSV Ingestion
      • Tutorials
        • Basics
          • Ingestion with SQL
          • CSV Ingestion
          • Basic S3 Example
          • Running Locally
        • Advanced
          • Scalable Ingestion
          • Scalable Queries
      • API Reference
    • AI & ML
      • Vector Search
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • Vector Search
            • Vector Databases
            • Algorithms
            • Distance Metrics
            • Updates
            • Deployment Methods
            • Architecture
            • Distributed Compute
          • Storage Format Spec
        • Tutorials
          • Basics
            • Ingestion & Querying
            • Updates
            • Deletions
            • Basic S3 Example
            • Running Locally
          • Advanced
            • Versioning
            • Time Traveling
            • Consolidation
            • Distributed Compute
            • RAG LLM
            • LLM Memory
            • File Search
            • Image Search
            • Protein Search
          • Performance
        • API Reference
      • ML Models
        • Introduction
        • Quickstart
        • Foundation
          • Basics
          • Storage
          • Cloud Execution
          • Why TileDB for Machine Learning
        • Tutorials
          • Ingestion
            • Data Ingestion
              • Dense Datasets
              • Sparse Datasets
            • ML Model Ingestion
          • Management
            • Array Schema
            • Machine Learning: Groups
            • Time Traveling
    • Life Sciences
      • Single-cell
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • Data Structures
            • Use of Apache Arrow
            • Join IDs
            • State Management
            • TileDB Cloud URIs
          • SOMA API Specification
        • Tutorials
          • Data Ingestion
          • Bulk Ingestion Tutorial
          • Data Access
          • Distributed Compute
          • Basic S3 Example
          • Multi-Experiment Queries
          • Appending Data to a SOMA Experiment
          • Add New Measurements
          • SQL Queries
          • Running Locally
          • Shapes in TileDB-SOMA
          • Drug Discovery App
        • Spatial
          • Introduction
          • Foundation
            • Spatial Data Model
            • Data Structures
          • Tutorials
            • Spatial Data Ingestion
            • Access Spatial Data
            • Manage Coordinate Spaces
        • API Reference
      • Population Genomics
        • Introduction
        • Quickstart
        • Foundation
          • Data Model
          • Key Concepts
            • The N+1 Problem
            • Architecture
            • Arrays
            • Ingestion
            • Reads
            • Variant Statistics
            • Annotations
            • User-Defined Functions
            • Tables and SQL
            • Distributed Compute
          • Storage Format Spec
        • Tutorials
          • Basics
            • Basic Ingestion
            • Basic Queries
            • Export to VCF
            • Add New Samples
            • Deleting Samples
            • Basic S3 Example
            • Basic TileDB Cloud
          • Advanced
            • Scalable Ingestion
            • Scalable Queries
            • Query Transforms
            • Handling Large Queries
            • Annotations
              • Finding Annotations
              • Embedded Annotations
              • External Annotations
              • Annotation VCFs
              • Ingesting Annotations
            • Variant Statistics
            • Tables and SQL
            • User-Defined Functions
            • Sample Metadata
            • Split VCF
          • Performance
        • API Reference
          • Command Line Interface
          • Python API
          • Cloud API
      • Biomedical Imaging
        • Introduction
        • Foundation
          • Data Model
          • Key Concepts
            • Arrays
            • Ingestion
            • Reads
            • User Defined Functions
          • Storage Format Spec
        • Quickstart
        • Tutorials
          • Basics
            • Ingestion
            • Read
              • OpenSlide
              • TileDB-Py
          • Advanced
            • Batched Ingestion
            • Chunked Ingestion
            • Machine Learning
              • PyTorch
            • Napari
    • Files
  • API Reference
  • Self-Hosting
    • Installation
    • Upgrades
    • Administrative Tasks
    • Image Customization
      • Customize User-Defined Function Images
      • AWS ECR Container Registry
      • Customize Jupyter Notebook Images
    • Single Sign-On
      • Configure Single Sign-On
      • OpenID Connect
      • Okta SCIM
      • Microsoft Entra
  • Glossary

On this page

  • Why Arrow?
  • Practical implications
  • DataFrame example
    • Define the schema
    • Perform a write
  • Additional resources
  1. Structure
  2. Life Sciences
  3. Single-cell
  4. Foundation
  5. Key Concepts
  6. Use of Apache Arrow

Use of Apache Arrow

life sciences
single cell (soma)
foundation
python
r
apache arrow
Learn about the Apache Arrow data types used in SOMA and how to work with them.

SOMA uses Apache Arrow for its in-memory type system. This page explains why Arrow is used and what this means for working with SOMA data structures.

Why Arrow?

Arrow is a widely adopted open standard for in-memory data representation. It provides a rich set of data types and is designed for high performance and interoperability across languages. Using Arrow, TileDB-SOMA can leverage these benefits and ensure that data is consistently represented across different systems and tools.

Practical implications

While SOMA data structures are typically created automatically by converting data from other formats (e.g., Seurat, AnnData, etc.), it’s also possible to create them manually, in which case Arrow data types must be specified.

DataFrame example

To demonstrate this, you will create a SOMADataFrame with a user-defined schema, which must be specified as an Arrow schema.

Start by importing the necessary libraries:

  • Python
  • R
import tempfile

import pyarrow as pa
import tiledbsoma
library(arrow)
library(tiledbsoma)

Define a URI to store the data use (this tutorial uses tempfile to create a temporary directory):

  • Python
  • R
URI = tempfile.mkdtemp(prefix="soma-dataframe-")
URI
URI <- tempfile(pattern = "soma-dataframe-")
URI

Define the schema

Create the Arrow schema, which defines the Arrow data types for each column.

  • Python
  • R
schema = pa.schema(
    [
        ("soma_joinid", pa.int64()),
        ("foo", pa.float64()),
        ("bar", pa.large_string()),
        ("baz", pa.bool_()),
    ]
)

schema
soma_joinid: int64
foo: double
bar: large_string
baz: bool
schema <- schema(
  soma_joinid = int64(),
  foo = float64(),
  bar = large_utf8(),
  baz = bool()
)

schema
Schema
soma_joinid: int64
foo: double
bar: large_string
baz: bool

Now, use this schema create a new SOMADataFrame:

  • Python
  • R
sdf = tiledbsoma.DataFrame.create(
    uri=URI, schema=schema, index_column_names=["soma_joinid"]
)
sdf <- tiledbsoma::SOMADataFrameCreate(
  uri = URI,
  schema = schema,
  index_column_names = "soma_joinid"
)

sdf
<SOMADataFrame>
  uri: /tmp/RtmplquLEM/soma-dataframe-abe75f7db8e0 
  dimensions: soma_joinid 
  attributes: foo, bar, baz 

This produced an empty SOMADataFrame with a TileDB schema that matches the provided Arrow schema.

TileDB-SOMA is strongly typed, which means all requests for a given Arrow type must be fulfilled or throw an error. This ensures that the API is self-consistent and predictable. For example, as you’ve seen, SOMA creation operations require an Arrow schema. Thus, the schema accessor returns the same type.

  • Python
  • R
sdf.schema
soma_joinid: int64 not null
foo: double
bar: large_string
baz: bool
sdf$schema()
Schema
soma_joinid: int64 not null
foo: double
bar: string
baz: bool

Perform a write

Similarly, when writing data to a SOMA object, it must be provided in the correct Arrow type. In this case, you will create a synthetic Arrow Table with the same schema used to create the SOMADataFrame.

  • Python
  • R
tbl = pa.Table.from_pydict(
    {
        "soma_joinid": [0, 1, 2, 3, 4],
        "foo": [4.1, 5.2, 6.3, 7.4, 8.5],
        "bar": ["apple", "ball", "cat", "dog", "egg"],
        "baz": [True, False, False, True, False],
    },
    schema=schema,
)

tbl
pyarrow.Table
soma_joinid: int64
foo: double
bar: large_string
baz: bool
----
soma_joinid: [[0,1,2,3,4]]
foo: [[4.1,5.2,6.3,7.4,8.5]]
bar: [["apple","ball","cat","dog","egg"]]
baz: [[true,false,false,true,false]]
tbl <- Table$create(
  soma_joinid = c(0, 1, 2, 3, 4),
  foo = c(4.1, 5.2, 6.3, 7.4, 8.5),
  bar = c("apple", "ball", "cat", "dog", "egg"),
  baz = c(TRUE, FALSE, FALSE, TRUE, FALSE),
  schema = schema
)

tbl
Table
5 rows x 4 columns
$soma_joinid <int64>
$foo <double>
$bar <large_string>
$baz <bool>

This table can now be written to the SOMADataFrame:

  • Python
  • R
sdf.write(tbl)
<DataFrame '/var/folders/nr/1dsl0n155wj7wv083km8t1540000gn/T/soma-dataframe-ml14qysp' (open for 'w')>
sdf$write(tbl)

Remember to close the table when you are done with it:

  • Python
  • R
sdf.close()
sdf$close()

Additional resources

Refer to the SOMA API specification for more technical details about SOMA’s use of Arrow.

Data Structures
Join IDs