public class Dataset extends Object implements Closeable
Closeable
interface to ensure proper resource management.| Modifier and Type | Class and Description |
|---|---|
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.
|
long |
calculateDataSize()
Calculate the size of the dataset.
|
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.
|
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)
Delete the config keys of the dataset.
|
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.
|
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.
|
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 |
replaceFieldMetadata(Map<Integer,Map<String,String>> fieldMetadataMap)
Replace target field metadata of the dataset.
|
void |
replaceSchemaMetadata(Map<String,String> metadata)
Replace the schema metadata of the dataset.
|
void |
restore()
Restore the currently checked out version of the dataset as the latest version.
|
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.
|
void |
updateConfig(Map<String,String> tableConfig)
Update the config of the dataset.
|
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 updateConfig(Map<String,String> tableConfig)
tableConfig - the config to updatepublic void deleteConfigKeys(Set<String> deleteKeys)
deleteKeys - the config keys to deletepublic void close()
close in interface Closeableclose in interface AutoCloseablepublic 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 void replaceSchemaMetadata(Map<String,String> metadata)
metadata - the new table metadatapublic void replaceFieldMetadata(Map<Integer,Map<String,String>> fieldMetadataMap)
fieldMetadataMap - field id to metadata mappublic 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.Copyright © 2025. All rights reserved.