Lance C/C++ Bindings
C ABI and header-only C++ RAII wrappers for the Lance columnar data format
Loading...
Searching...
No Matches
lance::Fragment Class Reference

#include <lance/detail/declarations.hpp>

Public Member Functions

 Fragment (LanceFragment *fragment)
 Adopt a handle from the C API; closed on destruction.
 
 Fragment (Fragment &&) noexcept=default
 
Fragment & operator= (Fragment &&) noexcept=default
 
 Fragment (const Fragment &)=delete
 
Fragment & operator= (const Fragment &)=delete
 
uint64_t id () const
 Native fragment ID.
 
uint64_t data_file_count () const
 Number of Native base data files; excludes overlays and the deletion file.
 
bool is_bound () const
 Whether this handle retains a dataset-bound native fragment.
 
DataFile data_file_at (size_t index) const
 Clone one native base data file from owned fragment metadata.
 
std::optional< DataFile > data_file_for_field (int32_t field_id) const
 
std::string metadata_json () const
 
void schema (ArrowSchema *out) const
 
LanceSchema native_schema () const
 Clone the fragment's native schema from its staged dataset snapshot.
 
uint64_t physical_rows () const
 Physical row count, including deleted rows. May perform data-file I/O.
 
uint64_t deleted_rows () const
 Deleted-row count. May load the deletion vector.
 
uint64_t logical_rows () const
 Logical row count from Native count_rows(None).
 
uint64_t read_version () const
 Dataset read version captured by this bound fragment.
 
Scanner scan () const
 Start a scanner over this fragment's owned snapshot.
 
void take (const uint32_t *indices, size_t num_indices, const std::vector< std::string > &columns, ArrowArrayStream *out) const
 
void take (const uint32_t *indices, size_t num_indices, ArrowArrayStream *out) const
 Take fragment-local logical rows with the full logical schema.
 
ArrowStream take (const uint32_t *indices, size_t num_indices, const std::vector< std::string > &columns) const
 
ArrowStream take (const uint32_t *indices, size_t num_indices) const
 
ArrowStream take (std::span< const uint32_t > indices, const std::vector< std::string > &columns) const
 
ArrowStream take (std::span< const uint32_t > indices) const
 
uint64_t count_rows (std::optional< std::string > filter=std::nullopt) const
 
std::optional< Fragment > delete_if (const std::string &predicate) const
 
std::pair< Fragment, LanceSchema > add_columns_sql (const std::vector< SqlColumn > &columns, std::optional< uint32_t > batch_size=std::nullopt) const
 
std::pair< Fragment, LanceSchema > add_columns_nulls (const ArrowSchema *columns) const
 Add all-null columns described by a borrowed Arrow schema.
 
std::pair< Fragment, LanceSchema > add_columns_reader (ArrowArrayStream *stream, std::optional< uint32_t > batch_size=std::nullopt) const
 Add columns from a consumed Arrow stream using Native Reader semantics.
 
std::pair< Fragment, LanceSchema > add_columns_batch_udf (const BatchUDF &udf, std::optional< std::vector< std::string > > read_columns=std::nullopt, std::optional< uint32_t > batch_size=std::nullopt) const
 Add columns through the shared BatchUDF callback adapter.
 
std::pair< Fragment, LanceSchema > add_columns_batch_udf (const BatchUDFV2 &udf, std::optional< std::vector< std::string > > read_columns=std::nullopt, std::optional< uint32_t > batch_size=std::nullopt) const
 Add columns through the shared schema-aware BatchUDF adapter.
 
std::pair< Fragment, LanceSchema > merge_columns (ArrowArrayStream *stream, const std::string &left_on, const std::string &right_on) const
 Merge a consumed right-hand Arrow stream into this bound fragment.
 
FragmentUpdateColumnsResult update_columns (ArrowArrayStream *stream, const std::string &left_on, const std::string &right_on) const
 
DataReplacementGroup write_columns (const LanceSchema &schema, ArrowArrayStream *stream) const
 Stage a replacement data file using the manifest's default version.
 
DataReplacementGroup write_column_with_version (const LanceSchema &schema, ArrowArrayStream *stream, LanceFileFormatVersion file_version) const
 Stage a replacement data file using an explicit native file version.
 
std::optional< Fragment > delete_rows (const std::vector< uint32_t > &offsets) const
 
FragmentOverlayWriter write_overlay (const LanceSchema &schema) const
 
const LanceFragment * c_handle () const
 

Static Public Member Functions

static Fragment from_data_files (uint64_t fragment_id, const std::vector< const DataFile * > &data_files, std::optional< uint64_t > physical_rows=std::nullopt)
 
static Fragment create (const std::string &dataset_uri, ArrowArrayStream *stream, uint64_t fragment_id, const FragmentCreateOptions &options={}, const std::vector< std::pair< std::string, std::string > > &storage_opts={}, const Session *session=nullptr)
 
static std::vector< Fragment > create_many (const std::string &dataset_uri, ArrowArrayStream *stream, const FragmentCreateOptions &options={}, const std::vector< std::pair< std::string, std::string > > &storage_opts={}, const Session *session=nullptr)
 
static Fragment create_from_file (const Dataset &dataset, const std::string &filename, uint64_t fragment_id, std::optional< uint64_t > physical_rows=std::nullopt)
 

Detailed Description

RAII handle over a dataset-bound or independently constructed fragment. Native FileFragment owns an Arc<Dataset>, so bound handles remain valid and keep reading the same dataset version after the source Dataset is closed or mutated. Detached handles own copied native metadata and support operation construction without dataset access.

Definition at line 2554 of file declarations.hpp.

Constructor & Destructor Documentation

◆ Fragment() [1/3]

lance::Fragment::Fragment ( LanceFragment * fragment)
explicit

Adopt a handle from the C API; closed on destruction.

◆ Fragment() [2/3]

lance::Fragment::Fragment ( Fragment && )
defaultnoexcept

◆ Fragment() [3/3]

lance::Fragment::Fragment ( const Fragment & )
delete

Member Function Documentation

◆ add_columns_batch_udf() [1/2]

std::pair< Fragment, LanceSchema > lance::Fragment::add_columns_batch_udf ( const BatchUDF & udf,
std::optional< std::vector< std::string > > read_columns = std::nullopt,
std::optional< uint32_t > batch_size = std::nullopt ) const

Add columns through the shared BatchUDF callback adapter.

◆ add_columns_batch_udf() [2/2]

std::pair< Fragment, LanceSchema > lance::Fragment::add_columns_batch_udf ( const BatchUDFV2 & udf,
std::optional< std::vector< std::string > > read_columns = std::nullopt,
std::optional< uint32_t > batch_size = std::nullopt ) const

Add columns through the shared schema-aware BatchUDF adapter.

◆ add_columns_nulls()

std::pair< Fragment, LanceSchema > lance::Fragment::add_columns_nulls ( const ArrowSchema * columns) const

Add all-null columns described by a borrowed Arrow schema.

◆ add_columns_reader()

std::pair< Fragment, LanceSchema > lance::Fragment::add_columns_reader ( ArrowArrayStream * stream,
std::optional< uint32_t > batch_size = std::nullopt ) const

Add columns from a consumed Arrow stream using Native Reader semantics.

◆ add_columns_sql()

std::pair< Fragment, LanceSchema > lance::Fragment::add_columns_sql ( const std::vector< SqlColumn > & columns,
std::optional< uint32_t > batch_size = std::nullopt ) const

Add SQL-derived columns to this bound fragment.

batch_size == std::nullopt maps to native None; an engaged zero is forwarded as Some(0). Returns detached fragment metadata and the complete native final schema for a later Merge operation.

◆ c_handle()

const LanceFragment * lance::Fragment::c_handle ( ) const

◆ count_rows()

uint64_t lance::Fragment::count_rows ( std::optional< std::string > filter = std::nullopt) const

Count fragment rows. std::nullopt calls native count_rows(None); an empty string is passed as an explicit native filter.

◆ create()

static Fragment lance::Fragment::create ( const std::string & dataset_uri,
ArrowArrayStream * stream,
uint64_t fragment_id,
const FragmentCreateOptions & options = {},
const std::vector< std::pair< std::string, std::string > > & storage_opts = {},
const Session * session = nullptr )
static

Create one fragment without publishing a version.

Maps to native FragmentCreateBuilder::write(source, Some(fragment_id)). Native owns schema inference and compatibility, file format, physical row counts and error semantics; an empty input fails with the native "Input data was empty." error. The stream is consumed on every return path, including a null stream pointer (which is rejected unconsumed) and local conversion failures. A null options.schema keeps native inference.

Returns independently owned detached metadata that stays valid after the source dataset, schema and session are closed. Closing it never deletes the written data file; publish the fragment with an Append transaction.

◆ create_from_file()

static Fragment lance::Fragment::create_from_file ( const Dataset & dataset,
const std::string & filename,
uint64_t fragment_id,
std::optional< uint64_t > physical_rows = std::nullopt )
static

Create one fragment from an existing Lance data file in dataset's data directory.

Maps to native FileFragment::create_from_file. filename is relative to the dataset's data directory. physical_rows == std::nullopt maps to native None; an engaged value maps to Some(value). Native owns file version, schema compatibility and physical-row validation. The dataset supplies the target snapshot and is not modified. A file whose stored schema native cannot project to the dataset schema is rejected, as with Blob v2 data files.

◆ create_many()

static std::vector< Fragment > lance::Fragment::create_many ( const std::string & dataset_uri,
ArrowArrayStream * stream,
const FragmentCreateOptions & options = {},
const std::vector< std::pair< std::string, std::string > > & storage_opts = {},
const Session * session = nullptr )
static

Create zero or more fragments without publishing a version.

Maps to native FragmentCreateBuilder::write_fragments, so options.write.params.max_rows_per_file splitting and fragment ID assignment stay native. The stream follows the same consumption contract as create; an empty input returns an empty vector.

◆ data_file_at()

DataFile lance::Fragment::data_file_at ( size_t index) const

Clone one native base data file from owned fragment metadata.

◆ data_file_count()

uint64_t lance::Fragment::data_file_count ( ) const

Number of Native base data files; excludes overlays and the deletion file.

◆ data_file_for_field()

std::optional< DataFile > lance::Fragment::data_file_for_field ( int32_t field_id) const

Find the native base data file that stores a field ID. Missing fields return std::nullopt; a negative field ID is an invalid argument.

◆ delete_if()

std::optional< Fragment > lance::Fragment::delete_if ( const std::string & predicate) const

Delete rows from this fragment without publishing a transaction.

The source handle remains usable. The returned fragment owns the new deletion-file metadata and can be scanned before publication. A full deletion returns std::nullopt.

◆ delete_rows()

std::optional< Fragment > lance::Fragment::delete_rows ( const std::vector< uint32_t > & offsets) const

Add physical row offsets to a clone and return updated bound metadata. A full deletion returns std::nullopt.

◆ deleted_rows()

uint64_t lance::Fragment::deleted_rows ( ) const

Deleted-row count. May load the deletion vector.

◆ from_data_files()

static Fragment lance::Fragment::from_data_files ( uint64_t fragment_id,
const std::vector< const DataFile * > & data_files,
std::optional< uint64_t > physical_rows = std::nullopt )
static

Construct detached native Fragment metadata from borrowed data files.

The data files are cloned in input order. physical_rows == / std::nullopt maps to native None; all other metadata retains native Fragment::new defaults. A fragment ID of zero requests native commit-time allocation. Schema coverage and physical_rows are caller metadata; this constructor does not infer or revalidate them.

◆ id()

uint64_t lance::Fragment::id ( ) const

Native fragment ID.

◆ is_bound()

bool lance::Fragment::is_bound ( ) const

Whether this handle retains a dataset-bound native fragment.

◆ logical_rows()

uint64_t lance::Fragment::logical_rows ( ) const

Logical row count from Native count_rows(None).

◆ merge_columns()

std::pair< Fragment, LanceSchema > lance::Fragment::merge_columns ( ArrowArrayStream * stream,
const std::string & left_on,
const std::string & right_on ) const

Merge a consumed right-hand Arrow stream into this bound fragment.

◆ metadata_json()

std::string lance::Fragment::metadata_json ( ) const

Native Fragment metadata serialized as JSON. Includes base data files, overlays, deletion-file metadata, row-id/version metadata, and the optional physical_rows value.

◆ native_schema()

LanceSchema lance::Fragment::native_schema ( ) const

Clone the fragment's native schema from its staged dataset snapshot.

◆ operator=() [1/2]

Fragment & lance::Fragment::operator= ( const Fragment & )
delete

◆ operator=() [2/2]

Fragment & lance::Fragment::operator= ( Fragment && )
defaultnoexcept

◆ physical_rows()

uint64_t lance::Fragment::physical_rows ( ) const

Physical row count, including deleted rows. May perform data-file I/O.

◆ read_version()

uint64_t lance::Fragment::read_version ( ) const

Dataset read version captured by this bound fragment.

◆ scan()

Scanner lance::Fragment::scan ( ) const

Start a scanner over this fragment's owned snapshot.

◆ schema()

void lance::Fragment::schema ( ArrowSchema * out) const

Export the logical dataset schema through Arrow C Data Interface. out is caller-owned; release it exactly once.

◆ take() [1/6]

ArrowStream lance::Fragment::take ( const uint32_t * indices,
size_t num_indices ) const

Take fragment-local logical rows with all columns and return the owning stream. Ownership and validation follow the projecting overload above.

◆ take() [2/6]

void lance::Fragment::take ( const uint32_t * indices,
size_t num_indices,
ArrowArrayStream * out ) const

Take fragment-local logical rows with the full logical schema.

◆ take() [3/6]

ArrowStream lance::Fragment::take ( const uint32_t * indices,
size_t num_indices,
const std::vector< std::string > & columns ) const

Take fragment-local logical rows and return the owning stream.

The projection, explicit-empty-projection behavior and native validation are the same as the raw-out overload. The returned ArrowStream releases the native stream exactly once, on destruction or reset(); moving it transfers ownership and leaves the source empty. out from the raw-out overload remains caller-owned.

◆ take() [4/6]

void lance::Fragment::take ( const uint32_t * indices,
size_t num_indices,
const std::vector< std::string > & columns,
ArrowArrayStream * out ) const

Take fragment-local logical rows by index with an explicit projection. Indices retain the selected core's ordering and duplicate constraints. out is caller-owned and its non-null release must be called exactly once. An empty columns vector is an explicit empty projection and produces a zero-column batch with the requested row count.

◆ take() [5/6]

ArrowStream lance::Fragment::take ( std::span< const uint32_t > indices) const

Borrow all-column indices from a contiguous range and return the owning stream. Ownership follows the overload above.

◆ take() [6/6]

ArrowStream lance::Fragment::take ( std::span< const uint32_t > indices,
const std::vector< std::string > & columns ) const

Borrow indices from a contiguous range and return the owning stream. The range is read only during this call. Empty-range and projection behavior are inherited from the pointer/count overload above.

◆ update_columns()

FragmentUpdateColumnsResult lance::Fragment::update_columns ( ArrowArrayStream * stream,
const std::string & left_on,
const std::string & right_on ) const

Rewrite existing columns through a native join and return matched physical offsets with the updated metadata.

◆ write_column_with_version()

DataReplacementGroup lance::Fragment::write_column_with_version ( const LanceSchema & schema,
ArrowArrayStream * stream,
LanceFileFormatVersion file_version ) const

Stage a replacement data file using an explicit native file version.

◆ write_columns()

DataReplacementGroup lance::Fragment::write_columns ( const LanceSchema & schema,
ArrowArrayStream * stream ) const

Stage a replacement data file using the manifest's default version.

◆ write_overlay()

FragmentOverlayWriter lance::Fragment::write_overlay ( const LanceSchema & schema) const

Open an overlay writer for this bound fragment. The schema may be a compatible subset of the fragment schema. Commit the resulting overlay with the dataset read version used to open the writer. Native overlays are experimental. For release builds, set LANCE_ENABLE_UNSTABLE_DATA_OVERLAY_FILES=1 in every process that reads or modifies an overlay dataset, including before publication.


The documentation for this class was generated from the following file: