How to use the tiledb.VFS function in tiledb

To help you get started, we’ve selected a few tiledb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TileDB-Inc / TileDB-Py / examples / vfs.py View on Github external
def read():
    # Create TileDB VFS
    vfs = tiledb.VFS()

    # Read binary data
    f = vfs.open("tiledb_vfs.bin", "rb")
    f1 = struct.unpack("f", vfs.read(f, 0, 4))[0]
    s1 = bytes.decode(vfs.read(f, 4, 12), "utf-8")
    print("Binary read:\n{}\n{}".format(f1, s1))

    vfs.close(f)
github TileDB-Inc / TileDB-Py / examples / libtiledb / tiledb_config.py View on Github external
# Set values
    config["vfs.s3.connect_timeout_ms"] = 5000
    config["vfs.s3.endpoint_override"] = "localhost:88880"

    # Get values
    tile_cache_size = config["sm.tile_cache_size"]
    print("\nTile cache size: ", tile_cache_size)

    # Print only the s3 settings
    print("\nVFS S3 settings:")
    for p, v in config.items(prefix="vfs.s3."):
        print("{0!r} : {1!r}".format(p, v))

    # Assign a config object to Ctx and VFS
    ctx = tiledb.Ctx(config=config)
    vfs = tiledb.VFS(ctx, config=config)
github TileDB-Inc / TileDB-Py / examples / libtiledb / tiledb_vfs_read.py View on Github external
def main():
    # create TileDB context
    ctx = tiledb.Ctx()

    # create TileDB VFS
    vfs = tiledb.VFS(ctx)

    # Read binary data
    fh = vfs.open("tiledb_vfs.bin", mode='r')

    nbytes = struct.calcsize("f")
    f1 = vfs.read(fh, 0, nbytes)
    s1 = vfs.read(fh, nbytes, 12)

    print("Binary read:\n{0:0.1f}\n{1!r}".format(struct.unpack("f", f1)[0], s1))

    # Close and remove the binary file
    vfs.close(fh)
    vfs.remove_file("tiledb_vfs.bin")
github TileDB-Inc / TileDB-Py / examples / vfs.py View on Github external
def dirs_files():
    # Create TileDB VFS
    vfs = tiledb.VFS()

    # Create directory
    if not vfs.is_dir("dir_A"):
        vfs.create_dir(path("dir_A"))
        print("Created 'dir_A'")
    else:
        print("'dir_A' already exists")

    # Creating an (empty) file
    if not vfs.is_file("dir_A/file_A"):
        vfs.touch(path("dir_A/file_A"))
        print("Created empty file 'dir_A/file_A'")
    else:
        print("'dir_A/file_A' already exists")

    # Getting the file size
github TileDB-Inc / TileDB-Py / examples / errors.py View on Github external
#   https://docs.tiledb.io/en/latest/tutorials/errors.html
#
# This example shows how to catch errors in TileDB.
#

import tiledb

# Catch an error
try:
    tiledb.group_create("my_group")
    tiledb.group_create("my_group")
except tiledb.TileDBError as e:
    print("TileDB exception: %s" % e.message)

# clean up
if tiledb.VFS().is_dir("my_group"):
    tiledb.remove("my_group")
github TileDB-Inc / TileDB-Py / tiledb / dataframe_.py View on Github external
'array'
    """
    try:
        import pandas
    except ImportError as exc:
        print("tiledb.from_csv requires pandas")
        raise

    tiledb_args = parse_tiledb_kwargs(kwargs)
    multi_file = False
    debug = tiledb_args.get('debug', False)

    if isinstance(csv_file, str) and not os.path.isfile(csv_file):
        # for non-local files, use TileDB VFS i/o
        ctx = tiledb_args.get('ctx', tiledb.default_ctx())
        vfs = tiledb.VFS(ctx=ctx)
        csv_file = tiledb.FileIO(vfs, csv_file, mode='rb')
    elif isinstance(csv_file, (list, tuple)):
        # TODO may be useful to support a callback here
        multi_file = True

    mode = kwargs.pop('mode', None)
    if mode is not None:
        tiledb_args['mode'] = mode
        # For schema_only mode we need to pass a max read count into
        #   pandas.read_csv
        # Note that 'nrows' is a pandas arg!
        if mode == 'schema_only' and not 'nrows' in kwargs:
            kwargs['nrows'] = 500
        elif mode not in ['ingest', 'append']:
            raise TileDBError("Invalid mode specified ('{}')".format(mode))
github TileDB-Inc / TileDB-Py / examples / vfs.py View on Github external
def write():
    # Create TileDB VFS
    vfs = tiledb.VFS()

    # Create VFS file handle
    f = vfs.open("tiledb_vfs.bin", "wb")

    # Write binary data
    vfs.write(f, struct.pack("f", 153.0))
    vfs.write(f, "abcd".encode("utf-8"))
    vfs.close(f)

    # Write binary data again - this will overwrite the previous file
    f = vfs.open("tiledb_vfs.bin", "wb")
    vfs.write(f, struct.pack("f", 153.1))
    vfs.write(f, "abcdef".encode("utf-8"))
    vfs.close(f)

    # Append binary data to existing file (this will NOT work on S3)