public class Dataset extends Object implements Closeable
Closeable
interface to ensure proper resource management.| Modifier and Type | Class and Description |
|---|---|
class |
Dataset.Branches
Branch operations of the dataset.
|
class |
Dataset.Tags
Tag operations of the dataset.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumns(org.apache.arrow.c.ArrowArrayStream stream,
Optional<Long> batchSize)
Add columns to the dataset.
|
void |
addColumns(List<org.apache.arrow.vector.types.pojo.Field> fields)
Add columns to the dataset.
|
void |
addColumns(org.apache.arrow.vector.types.pojo.Schema schema)
Add columns to the dataset.
|
void |
addColumns(SqlExpressions sqlExpressions,
Optional<Long> batchSize)
Add columns to the dataset.
|
org.apache.arrow.memory.BufferAllocator |
allocator() |
void |
alterColumns(List<ColumnAlteration> columnAlterations)
Alter columns in the dataset.
|
Dataset.Branches |
branches()
Branch operations aligned with Rust's Dataset branch APIs.
|
long |
calculateDataSize()
Calculate the size of the dataset.
|
Dataset |
checkout(Ref ref)
Checkout using a unified
Ref which can be a tag, the latest version on main/branch or a
specified (branch_name, version_number). |
void |
checkoutLatest()
Checkout the dataset to the latest version.
|
Dataset |
checkoutTag(String tag)
Checks out a specific tag of the dataset.
|
Dataset |
checkoutVersion(long version)
Checks out a specific version of the dataset.
|
void |
close()
Closes this dataset and releases any system resources associated with it.
|
boolean |
closed()
Checks if the dataset is closed.
|
static Dataset |
commit(org.apache.arrow.memory.BufferAllocator allocator,
String path,
FragmentOperation operation,
Optional<Long> readVersion)
Deprecated.
|
static Dataset |
commit(org.apache.arrow.memory.BufferAllocator allocator,
String path,
FragmentOperation operation,
Optional<Long> readVersion,
Map<String,String> storageOptions)
Deprecated.
|
static Dataset |
commitAppend(String path,
Optional<Long> readVersion,
List<FragmentMetadata> fragmentsMetadata,
Map<String,String> storageOptions)
Deprecated.
|
static Dataset |
commitOverwrite(String path,
long arrowSchemaMemoryAddress,
Optional<Long> readVersion,
List<FragmentMetadata> fragmentsMetadata,
Map<String,String> storageOptions)
Deprecated.
|
Dataset |
commitTransaction(Transaction transaction)
Commit a single transaction and return a new Dataset with the new version.
|
void |
compact()
Compact the dataset with default options.
|
void |
compact(CompactionOptions options)
Compact the dataset to improve performance.
|
long |
countRows()
Count the number of rows in the dataset.
|
long |
countRows(String filter)
Count the number of rows in the dataset.
|
static Dataset |
create(org.apache.arrow.memory.BufferAllocator allocator,
org.apache.arrow.c.ArrowArrayStream stream,
String path,
WriteParams params)
Create a dataset with given stream.
|
static Dataset |
create(org.apache.arrow.memory.BufferAllocator allocator,
String path,
org.apache.arrow.vector.types.pojo.Schema schema,
WriteParams params)
Creates an empty dataset.
|
void |
createIndex(List<String> columns,
IndexType indexType,
Optional<String> name,
IndexParams params,
boolean replace)
Creates a new index on the dataset.
|
void |
delete(String predicate)
Delete rows of data by predicate.
|
void |
deleteConfigKeys(Set<String> deleteKeys)
Deprecated.
Use
newTransactionBuilder() with UpdateConfig operation instead |
static void |
drop(String path,
Map<String,String> storageOptions)
Drop a Dataset.
|
void |
dropColumns(List<String> columns)
Drop columns from the dataset.
|
Map<String,String> |
getConfig()
Get the table config of the dataset.
|
Fragment |
getFragment(int fragmentId) |
List<Fragment> |
getFragments()
Get all fragments in this dataset.
|
LanceSchema |
getLanceSchema()
Get the
LanceSchema of the dataset with field ids. |
org.apache.arrow.vector.types.pojo.Schema |
getSchema()
Gets the arrow schema of the dataset.
|
Map<String,String> |
getTableMetadata()
Get the table metadata of the dataset.
|
Version |
getVersion()
Gets the currently checked out version of the dataset.
|
long |
latestVersion() |
List<String> |
listIndexes() |
List<Version> |
listVersions()
Get the version history of the dataset.
|
MergeInsertResult |
mergeInsert(MergeInsertParams mergeInsert,
org.apache.arrow.c.ArrowArrayStream source)
Merge source data with the existing target data.
|
LanceScanner |
newScan()
Create a new Dataset Scanner.
|
LanceScanner |
newScan(long batchSize)
Create a new Dataset Scanner.
|
LanceScanner |
newScan(ScanOptions options)
Create a new Dataset Scanner.
|
Transaction.Builder |
newTransactionBuilder()
Create a new transaction builder at current version for the dataset.
|
static Dataset |
open(org.apache.arrow.memory.BufferAllocator allocator,
String path,
ReadOptions options)
Open a dataset from the specified path with additional options.
|
static Dataset |
open(String path)
Open a dataset from the specified path.
|
static Dataset |
open(String path,
org.apache.arrow.memory.BufferAllocator allocator)
Open a dataset from the specified path.
|
static Dataset |
open(String path,
ReadOptions options)
Open a dataset from the specified path.
|
Optional<Transaction> |
readTransaction()
Get the
Transaction of the dataset at the current version. |
void |
restore()
Restore the currently checked out version of the dataset as the latest version.
|
Dataset |
shallowClone(String targetPath,
Ref ref) |
Dataset |
shallowClone(String targetPath,
Ref ref,
Map<String,String> storageOptions)
Shallow clone the specified tag into a new dataset at the target path.
|
SqlQuery |
sql(String sql)
Execute SQL query on the dataset.
|
Dataset.Tags |
tags()
Returns a
Dataset.Tags instance for performing tag-related operations on the dataset. |
org.apache.arrow.vector.ipc.ArrowReader |
take(List<Long> indices,
List<String> columns)
Select rows of data by index.
|
List<BlobFile> |
takeBlobs(List<Long> rowIds,
String column)
Open blob files for given row ids on a blob column.
|
List<BlobFile> |
takeBlobsByIndices(List<Long> rowIndices,
String column)
Open blob files for given row indices on a blob column.
|
void |
updateConfig(Map<String,String> tableConfig)
Deprecated.
Use
newTransactionBuilder() with UpdateConfig operation instead |
String |
uri()
Gets the URI of the dataset.
|
long |
version()
Get the currently checked out version id of the dataset
|
public static Dataset create(org.apache.arrow.memory.BufferAllocator allocator, String path, org.apache.arrow.vector.types.pojo.Schema schema, WriteParams params)
allocator - the buffer allocatorpath - dataset urischema - dataset schemaparams - write paramspublic static Dataset create(org.apache.arrow.memory.BufferAllocator allocator, org.apache.arrow.c.ArrowArrayStream stream, String path, WriteParams params)
allocator - buffer allocatorstream - arrow streampath - dataset uriparams - write parameterspublic static Dataset open(String path)
path - file pathpublic static Dataset open(String path, ReadOptions options)
path - file pathoptions - the open optionspublic static Dataset open(String path, org.apache.arrow.memory.BufferAllocator allocator)
path - file pathallocator - Arrow buffer allocatorpublic static Dataset open(org.apache.arrow.memory.BufferAllocator allocator, String path, ReadOptions options)
allocator - Arrow buffer allocatorpath - file pathoptions - the open options@Deprecated public static Dataset commit(org.apache.arrow.memory.BufferAllocator allocator, String path, FragmentOperation operation, Optional<Long> readVersion)
Transaction insteadallocator - the buffer allocatorpath - The file path of the dataset to open.operation - The operation to apply to the dataset.readVersion - The version of the dataset that was used as the base for the changes. This
is not needed for overwrite or restore operations.Dataset linked to the opened dataset.@Deprecated public static Dataset commit(org.apache.arrow.memory.BufferAllocator allocator, String path, FragmentOperation operation, Optional<Long> readVersion, Map<String,String> storageOptions)
@Deprecated public static Dataset commitAppend(String path, Optional<Long> readVersion, List<FragmentMetadata> fragmentsMetadata, Map<String,String> storageOptions)
Transaction instead@Deprecated public static Dataset commitOverwrite(String path, long arrowSchemaMemoryAddress, Optional<Long> readVersion, List<FragmentMetadata> fragmentsMetadata, Map<String,String> storageOptions)
Transaction insteadpublic org.apache.arrow.memory.BufferAllocator allocator()
public Transaction.Builder newTransactionBuilder()
Transaction.Builder linked to the opened dataset.public Dataset commitTransaction(Transaction transaction)
transaction - The transaction to commitDataset linked to committed version.public static void drop(String path, Map<String,String> storageOptions)
path - The file path of the datasetstorageOptions - Storage optionspublic void addColumns(SqlExpressions sqlExpressions, Optional<Long> batchSize)
sqlExpressions - The SQL expressions to add columnsbatchSize - The number of rows to read at a time from the source dataset when applying the
transform.public void addColumns(org.apache.arrow.c.ArrowArrayStream stream,
Optional<Long> batchSize)
stream - The Arrow Array Stream generated by arrow reader to add columns.batchSize - The number of rows to read at a time from the source dataset when applying the
transform.public void addColumns(org.apache.arrow.vector.types.pojo.Schema schema)
schema - The Arrow schema definitions to add columns.public void addColumns(List<org.apache.arrow.vector.types.pojo.Field> fields)
fields - The Arrow field definitions to add columns.public void dropColumns(List<String> columns)
columns - The columns to droppublic void alterColumns(List<ColumnAlteration> columnAlterations)
columnAlterations - The list of columns need to be altered.public LanceScanner newScan()
public LanceScanner newScan(long batchSize)
batchSize - the scan options with batch size, columns filter, and substraitpublic LanceScanner newScan(ScanOptions options)
options - the scan optionspublic org.apache.arrow.vector.ipc.ArrowReader take(List<Long> indices, List<String> columns) throws IOException
indices - the indices to takecolumns - the columns to takeIOExceptionpublic void delete(String predicate)
predicate - the predicate to deletepublic String uri()
public long version()
public Version getVersion()
public List<Version> listVersions()
public long latestVersion()
public void checkoutLatest()
public Dataset checkoutVersion(long version)
version - the version to check outpublic Dataset checkoutTag(String tag)
tag - the tag to check outpublic void restore()
public void createIndex(List<String> columns, IndexType indexType, Optional<String> name, IndexParams params, boolean replace)
columns - the columns to index fromindexType - the index typename - the name of the created indexparams - index paramsreplace - whether to replace the existing indexpublic long countRows()
public long countRows(String filter)
filter - the filter expr to count rowpublic long calculateDataSize()
public List<Fragment> getFragments()
Fragment.public org.apache.arrow.vector.types.pojo.Schema getSchema()
public LanceSchema getLanceSchema()
LanceSchema of the dataset with field ids.public Optional<Transaction> readTransaction()
Transaction of the dataset at the current version.public Map<String,String> getConfig()
public void compact(CompactionOptions options)
This operation performs several optimizations:
options - compaction options to control the behaviorpublic void compact()
@Deprecated public void updateConfig(Map<String,String> tableConfig)
newTransactionBuilder() with UpdateConfig operation insteadtableConfig - the config to update@Deprecated public void deleteConfigKeys(Set<String> deleteKeys)
newTransactionBuilder() with UpdateConfig operation insteaddeleteKeys - the config keys to deletepublic void close()
close in interface Closeableclose in interface AutoCloseablepublic List<BlobFile> takeBlobs(List<Long> rowIds, String column)
rowIds - stable row ids (row addresses)column - blob column namepublic List<BlobFile> takeBlobsByIndices(List<Long> rowIndices, String column)
rowIndices - row offsets within datasetcolumn - blob column namepublic boolean closed()
public Fragment getFragment(int fragmentId)
public Dataset.Tags tags()
Dataset.Tags instance for performing tag-related operations on the dataset.Tags instance for dataset tag operationsDataset.Tagspublic Dataset.Branches branches()
public Dataset checkout(Ref ref)
Ref which can be a tag, the latest version on main/branch or a
specified (branch_name, version_number).ref - the checkout referencepublic Map<String,String> getTableMetadata()
public SqlQuery sql(String sql)
sql - SELECT statement to execute. The default FROM table name is `dataset`, for example:
SELECT * FROM `dataset` LIMIT 10. If FROM table name is a custom value, the SqlQuery.tableName(String) should be invoked to set the custom table name.public MergeInsertResult mergeInsert(MergeInsertParams mergeInsert, org.apache.arrow.c.ArrowArrayStream source)
This will take in the source, merge it with the existing target data, and insert new rows, update existing rows, and delete existing rows.
It is important that after merge insert, the current dataset is changed and should be closed. The merged new dataset is contained in the MergeInsertResult.
mergeInsert - merge insert optionssource - ArrowArrayStream source datapublic Dataset shallowClone(String targetPath, Ref ref, Map<String,String> storageOptions)
This creates a new dataset that references the data files from the source dataset without copying them. Only metadata is written at the destination.
targetPath - the URI to clone the dataset intoref - the referred version of the current datasetstorageOptions - Optional object store options for the destination dataset; empty uses
default store parametersCopyright © 2025. All rights reserved.