diff --git a/.gitignore b/.gitignore index c355b682..d626575e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,26 +4,14 @@ core/obj/* core/lib/* core/include/temp core/src/temp -tiledb_cmd/include/temp -tiledb_cmd/src/temp -tiledb_cmd/bin/* -tiledb_cmd/obj/* -la/bin/* -la/obj/* -la/include/*.tmp -la/src/*.tmp -gtest/obj/* +coverage.info +test/obj/* +test/bin/* Doxyfile.log doxyfile.inc -doxygen_sqlite3.db doxygen/html/ doxygen/latex/ -rvma/obj/ -rvma/bin/ -my_workspace* -.directory examples/bin/* examples/obj/* *temp* -.project -.cproject +*.DS_Store diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..9424ed44 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +#Adapted from http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/ +sudo: required +dist: trusty + +install: + #Install lcov and MPICH + - sudo apt-get -y install lcov mpich zlib1g-dev libssl-dev libgtest-dev + - cd /usr/src/gtest + - sudo cmake . + - sudo make + - sudo mv libgtest* /usr/lib/ + - cd $TRAVIS_BUILD_DIR + # install lcov to coveralls conversion + upload tool + - gem install coveralls-lcov + +before_script: + - lcov --directory . --zerocounters + +script: + - make -j 4 + - make test + - lcov --directory . --capture --output-file coverage.info + - lcov --list coverage.info # debug before upload + +after_success: diff --git a/LICENSE b/LICENSE index 1632c845..2f657671 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 MIT and Intel Corp. +Copyright (c) 2016 MIT and Intel Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index ff37b7c5..700263c1 100644 --- a/Makefile +++ b/Makefile @@ -1,84 +1,66 @@ -########## -# Macros # -########## +# **************** # +# Macros # +# **************** # OS := $(shell uname) -# Configuration flags -CONFIG_FLAGS = +# --- Configuration flags --- # +CPPFLAGS = -std=gnu++11 -fPIC -fvisibility=hidden \ + -D_FILE_OFFSET_BITS=64 -# Use of mmap function for reading -USE_MMAP = +# For the Travis integration +ifdef TRAVIS + CPPFLAGS += --coverage +endif +# --- Use of mmap function for reading --- # +USE_MMAP = ifeq ($(USE_MMAP),) USE_MMAP = 1 endif - ifeq ($(USE_MMAP),1) - CONFIG_FLAGS += -D_TILEDB_USE_MMAP -endif - -# Large file support -LFS_CFLAGS = -D_FILE_OFFSET_BITS=64 + CPPFLAGS += -D_TILEDB_USE_MMAP +endif -# Parallel sort +# --- Parallel sort --- # GNU_PARALLEL = - ifeq ($(GNU_PARALLEL),) GNU_PARALLEL = 1 endif - ifeq ($(GNU_PARALLEL),1) - CFLAGS = -fopenmp -DGNU_PARALLEL -else - CFLAGS = + CPPFLAGS += -DGNU_PARALLEL endif -# --- Debug/Release/Verbose mode handler --- # +# --- Debug/Release mode handler --- # BUILD = -VERBOSE = - ifeq ($(BUILD),) BUILD = release endif ifeq ($(BUILD),release) - CFLAGS += -DNDEBUG -O3 + CPPFLAGS += -DNDEBUG -O3 endif ifeq ($(BUILD),debug) - CFLAGS += -DDEBUG -O0 -g + CPPFLAGS += -DDEBUG -gdwarf-3 -g3 endif +# --- Verbose mode handler --- # +VERBOSE = ifeq ($(VERBOSE),) VERBOSE = 2 endif - ifeq ($(VERBOSE),0) - CFLAGS += -DNVERBOSE + CPPFLAGS += -DNVERBOSE endif - ifneq ($(VERBOSE),0) - CFLAGS += -DVERBOSE=$(VERBOSE) + CPPFLAGS += -DVERBOSE=$(VERBOSE) endif -# --- Set library path to Google Test shared objects --- # -LDFLAGS += -L$(PWD)/3rdparty/gtest/lib -LDFLAGS += -Wl,-R$(PWD)/3rdparty/gtest/lib `$$ORIGIN` - # --- Compilers --- # - -# C++ compiler -# CXX = g++ - -# MPI compiler for C++ -MPIPATH = #/opt/mpich/dev/intel/default/bin/ -MPICXX = mpicxx -CXX = $(MPIPATH)$(MPICXX) -lstdc++ -std=c++11 -fPIC -fvisibility=hidden \ - $(LFS_CFLAGS) $(CFLAGS) $(CONFIG_FLAGS) +CXX = g++ # --- Directories --- # -# Directories for the core code of TileDB CORE_INCLUDE_DIR = core/include CORE_INCLUDE_SUBDIRS = $(wildcard core/include/*) CORE_SRC_DIR = core/src @@ -103,24 +85,6 @@ CORE_LIB_REL_DIR = core/lib/release ifeq ($(BUILD),release) CORE_LIB_DIR = $(CORE_LIB_REL_DIR) endif - -# Directories for the command-line-based frontend of TileDB -TILEDB_CMD_INCLUDE_DIR = tiledb_cmd/include -TILEDB_CMD_SRC_DIR = tiledb_cmd/src -TILEDB_CMD_OBJ_DEB_DIR = tiledb_cmd/obj/debug -TILEDB_CMD_BIN_DEB_DIR = tiledb_cmd/bin/debug -ifeq ($(BUILD),debug) - TILEDB_CMD_OBJ_DIR = $(TILEDB_CMD_OBJ_DEB_DIR) - TILEDB_CMD_BIN_DIR = $(TILEDB_CMD_BIN_DEB_DIR) -endif -TILEDB_CMD_OBJ_REL_DIR = tiledb_cmd/obj/release -TILEDB_CMD_BIN_REL_DIR = tiledb_cmd/bin/release -ifeq ($(BUILD),release) - TILEDB_CMD_OBJ_DIR = $(TILEDB_CMD_OBJ_REL_DIR) - TILEDB_CMD_BIN_DIR = $(TILEDB_CMD_BIN_REL_DIR) -endif - -# Directories for the examples EXAMPLES_INCLUDE_DIR = examples/include EXAMPLES_SRC_DIR = examples/src EXAMPLES_OBJ_DEB_DIR = examples/obj/debug @@ -135,60 +99,30 @@ ifeq ($(BUILD),release) EXAMPLES_OBJ_DIR = $(EXAMPLES_OBJ_REL_DIR) EXAMPLES_BIN_DIR = $(EXAMPLES_BIN_REL_DIR) endif - -# Directories for TileDB tests TEST_SRC_SUBDIRS = $(wildcard test/src/*) TEST_SRC_DIR = test/src TEST_OBJ_DIR = test/obj TEST_BIN_DIR = test/bin - -# Directories for Linear Algebra applications -LA_INCLUDE_DIR = la/include -LA_SRC_DIR = la/src -LA_OBJ_DIR = la/obj -LA_BIN_DIR = la/bin - -# Directories for distributed applications -RVMA_INCLUDE_DIR = rvma/include -RVMA_SRC_DIR = rvma/src -RVMA_OBJ_DIR = rvma/obj -RVMA_BIN_DIR = rvma/bin - -# Directory for Doxygen documentation DOXYGEN_DIR = doxygen DOXYGEN_MAINPAGE = $(DOXYGEN_DIR)/mainpage.dox -# Manpages directories -MANPAGES_MAN_DIR = manpages/man -MANPAGES_HTML_DIR = manpages/html - -# Directories for the MPI files - not necessary if mpicxx used. -MPI_INCLUDE_DIR := . -MPI_LIB_DIR := . - -# Directories for the OpenMP files -OPENMP_INCLUDE_DIR = . -OPENMP_LIB_DIR = . - # --- Paths --- # +INCLUDE_PATHS = CORE_INCLUDE_PATHS = $(addprefix -I, $(CORE_INCLUDE_SUBDIRS)) -TILEDB_CMD_INCLUDE_PATHS = -I$(TILEDB_CMD_INCLUDE_DIR) +EXAMPLES_INCLUDE_PATHS = -I$(EXAMPLES_INCLUDE_DIR) TEST_INCLUDE_PATHS = $(addprefix -I, $(CORE_INCLUDE_SUBDIRS)) +LIBRARY_PATHS = -EXAMPLES_INCLUDE_PATHS = -I$(EXAMPLES_INCLUDE_DIR) -LA_INCLUDE_PATHS = -I$(LA_INCLUDE_DIR) -MPI_INCLUDE_PATHS = -I$(MPI_INCLUDE_DIR) -MPI_LIB_PATHS = -L$(MPI_LIB_DIR) -OPENMP_INCLUDE_PATHS = -L$(OPENMP_INCLUDE_DIR) -OPENMP_LIB_PATHS = -L$(OPENMP_LIB_DIR) - -# --- Libs --- # -MPI_LIB = -lmpi -OPENMP_LIB = -fopenmp +ifdef TRAVIS + LIBRARY_PATHS += --coverage +endif + +# --- Libraries --- # ZLIB = -lz OPENSSLLIB = -lcrypto +GTESTLIB = -lgtest -lgtest_main -# --- File Extensions --- # +# --- For the TileDB dynamic library --- # ifeq ($(OS), Darwin) SHLIB_EXT = dylib else @@ -196,80 +130,46 @@ else endif # --- Files --- # - -# Files of the TileDB core CORE_INCLUDE := $(foreach D,$(CORE_INCLUDE_SUBDIRS),$D/*.h) CORE_SRC := $(wildcard $(foreach D,$(CORE_SRC_SUBDIRS),$D/*.cc)) CORE_OBJ := $(patsubst $(CORE_SRC_DIR)/%.cc, $(CORE_OBJ_DIR)/%.o, $(CORE_SRC)) - -# Files of the TileDB command-line-based frontend -TILEDB_CMD_INCLUDE := $(wildcard $(TILEDB_CMD_INCLUDE_DIR)/*.h) -TILEDB_CMD_SRC := $(wildcard $(TILEDB_CMD_SRC_DIR)/*.cc) -TILEDB_CMD_OBJ := $(patsubst $(TILEDB_CMD_SRC_DIR)/%.cc,\ - $(TILEDB_CMD_OBJ_DIR)/%.o, $(TILEDB_CMD_SRC)) -TILEDB_CMD_BIN := $(patsubst $(TILEDB_CMD_SRC_DIR)/%.cc,\ - $(TILEDB_CMD_BIN_DIR)/%, $(TILEDB_CMD_SRC)) -# Files of the examples EXAMPLES_INCLUDE := $(wildcard $(EXAMPLES_INCLUDE_DIR)/*.h) EXAMPLES_SRC := $(wildcard $(EXAMPLES_SRC_DIR)/*.cc) EXAMPLES_OBJ := $(patsubst $(EXAMPLES_SRC_DIR)/%.cc,\ $(EXAMPLES_OBJ_DIR)/%.o, $(EXAMPLES_SRC)) EXAMPLES_BIN := $(patsubst $(EXAMPLES_SRC_DIR)/%.cc,\ $(EXAMPLES_BIN_DIR)/%, $(EXAMPLES_SRC)) - -# Files of the TileDB tests TEST_SRC := $(wildcard $(foreach D,$(TEST_SRC_SUBDIRS),$D/*.cc)) TEST_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cc, $(TEST_OBJ_DIR)/%.o, $(TEST_SRC)) -# Files of the Linear Algebra applications -LA_SRC := $(wildcard $(LA_SRC_DIR)/*.cc) -LA_OBJ := $(patsubst $(LA_SRC_DIR)/%.cc, $(LA_OBJ_DIR)/%.o, $(LA_SRC)) -LA_BIN := $(patsubst $(LA_SRC_DIR)/%.cc, $(LA_BIN_DIR)/%, $(LA_SRC)) +# **************** # +# General Targets # +# **************** # -# Files of the distributed applications -RVMA_SRC := $(wildcard $(RVMA_SRC_DIR)/*.c) -RVMA_OBJ := $(patsubst $(RVMA_SRC_DIR)/%.c, $(RVMA_OBJ_DIR)/%.o, $(RVMA_SRC)) -RVMA_BIN := $(patsubst $(RVMA_SRC_DIR)/%.c, $(RVMA_BIN_DIR)/%, $(RVMA_SRC)) +.PHONY: core examples test doc clean_core \ + clean_test clean_doc clean_examples clean -# Files for the HTML version of the Manpages -MANPAGES_MAN := $(wildcard $(MANPAGES_MAN_DIR)/*) -MANPAGES_HTML := $(patsubst $(MANPAGES_MAN_DIR)/%,\ - $(MANPAGES_HTML_DIR)/%.html, $(MANPAGES_MAN)) - -################### -# General Targets # -################### - -.PHONY: core examples check doc clean_core \ - clean_check clean_tiledb_cmd clean_examples \ - clean - -all: core libtiledb tiledb_cmd examples +all: core libtiledb core: $(CORE_OBJ) -libtiledb: core $(CORE_LIB_DIR)/libtiledb.$(SHLIB_EXT) $(CORE_LIB_DIR)/libtiledb.a - -tiledb_cmd: core $(TILEDB_CMD_OBJ) $(TILEDB_CMD_BIN) - -examples: core $(EXAMPLES_OBJ) $(EXAMPLES_BIN) +libtiledb: core $(CORE_LIB_DIR)/libtiledb.$(SHLIB_EXT) \ + $(CORE_LIB_DIR)/libtiledb.a -rvma: core $(RVMA_OBJ) #$(RVMA_BIN_DIR)/simple_test +examples: libtiledb $(EXAMPLES_OBJ) $(EXAMPLES_BIN) -html: $(MANPAGES_HTML) +doc: doxyfile.inc -doc: doxyfile.inc html - -check: libtiledb $(TEST_BIN_DIR)/tiledb_test +test: libtiledb $(TEST_BIN_DIR)/tiledb_test @echo "Running TileDB tests" @$(TEST_BIN_DIR)/tiledb_test -clean: clean_core clean_libtiledb clean_tiledb_cmd \ - clean_check clean_doc clean_examples +clean: clean_core clean_libtiledb \ + clean_test clean_doc clean_examples -######## -# Core # -######## +# **************** # +# Core # +# **************** # # --- Compilation and dependency genration --- # @@ -278,8 +178,7 @@ clean: clean_core clean_libtiledb clean_tiledb_cmd \ $(CORE_OBJ_DIR)/%.o: $(CORE_SRC_DIR)/%.cc @mkdir -p $(dir $@) @echo "Compiling $<" - @$(CXX) $(CORE_INCLUDE_PATHS) $(OPENMP_INCLUDE_PATHS) \ - $(MPI_INCLUDE_PATHS) -c $< $(ZLIB) $(OPENSSLLIB) -o $@ + @$(CXX) $(CPPFLAGS) $(INCLUDE_PATHS) $(CORE_INCLUDE_PATHS) -c $< -o $@ @$(CXX) -MM $(CORE_INCLUDE_PATHS) $< > $(@:.o=.d) @mv -f $(@:.o=.d) $(@:.o=.d.tmp) @sed 's|.*:|$@:|' < $(@:.o=.d.tmp) > $(@:.o=.d) @@ -292,9 +191,9 @@ clean_core: @rm -rf $(CORE_OBJ_DEB_DIR)/* $(CORE_OBJ_REL_DIR)/* \ $(CORE_BIN_DEB_DIR)/* $(CORE_BIN_REL_DIR)/* -############# -# libtiledb # -############# +# **************** # +# libtiledb # +# **************** # -include $(CORE_OBJ:%.o=%.d) @@ -315,7 +214,8 @@ endif $(CORE_LIB_DIR)/libtiledb.$(SHLIB_EXT): $(CORE_OBJ) @mkdir -p $(CORE_LIB_DIR) @echo "Creating dynamic library libtiledb.$(SHLIB_EXT)" - @$(CXX) $(SHLIB_FLAGS) $(SONAME) -o $@ $^ $(ZLIB) $(OPENSSLLIB) + @$(CXX) $(SHLIB_FLAGS) $(SONAME) -o $@ $^ $(LIBRARY_PATHS) $(ZLIB) \ + $(OPENSSLLIB) -fopenmp $(CORE_LIB_DIR)/libtiledb.a: $(CORE_OBJ) @mkdir -p $(CORE_LIB_DIR) @@ -325,46 +225,12 @@ $(CORE_LIB_DIR)/libtiledb.a: $(CORE_OBJ) # --- Cleaning --- # clean_libtiledb: - @echo "Cleaning libtiledb.$(SHLIB_EXT)" + @echo "Cleaning libtiledb" @rm -rf $(CORE_LIB_DEB_DIR)/* $(CORE_LIB_REL_DIR)/* -############## -# TileDB_cmd # -############## - -# --- Compilation and dependency genration --- # - --include $(TILEDB_CMD_OBJ:.o=.d) - -$(TILEDB_CMD_OBJ_DIR)/%.o: $(TILEDB_CMD_SRC_DIR)/%.cc - @mkdir -p $(TILEDB_CMD_OBJ_DIR) - @echo "Compiling $<" - @$(CXX) $(TILEDB_CMD_INCLUDE_PATHS) $(CORE_INCLUDE_PATHS) -c $< \ - $(ZLIB) $(OPENSSLLIB) -o $@ - @$(CXX) -MM $(TILEDB_CMD_INCLUDE_PATHS) \ - $(CORE_INCLUDE_PATHS) $< > $(@:.o=.d) - @mv -f $(@:.o=.d) $(@:.o=.d.tmp) - @sed 's|.*:|$@:|' < $(@:.o=.d.tmp) > $(@:.o=.d) - @rm -f $(@:.o=.d.tmp) - -# --- Linking --- # - -$(TILEDB_CMD_BIN_DIR)/%: $(TILEDB_CMD_OBJ_DIR)/%.o $(CORE_OBJ) - @mkdir -p $(TILEDB_CMD_BIN_DIR) - @echo "Creating $@" - @$(CXX) $(OPENMP_LIB_PATHS) $(OPENMP_LIB) $(MPI_LIB_PATHS) $(MPI_LIB) \ - -o $@ $^ $(ZLIB) $(OPENSSLLIB) - -# --- Cleaning --- # - -clean_tiledb_cmd: - @echo 'Cleaning tiledb_cmd' - @rm -f $(TILEDB_CMD_OBJ_DEB_DIR)/* $(TILEDB_CMD_OBJ_REL_DIR)/* \ - $(TILEDB_CMD_BIN_DEB_DIR)/* $(TILEDB_CMD_BIN_REL_DIR)/* - -############## -# Examples # -############## +# **************** # +# Examples # +# **************** # # --- Compilation and dependency genration --- # @@ -373,8 +239,8 @@ clean_tiledb_cmd: $(EXAMPLES_OBJ_DIR)/%.o: $(EXAMPLES_SRC_DIR)/%.cc @mkdir -p $(EXAMPLES_OBJ_DIR) @echo "Compiling $<" - @$(CXX) $(EXAMPLES_INCLUDE_PATHS) $(CORE_INCLUDE_PATHS) -c $< \ - $(ZLIB) $(OPENSSLLIB) -o $@ + @$(CXX) $(CPPFLAGS) $(INCLUDE_PATHS) $(EXAMPLES_INCLUDE_PATHS) \ + $(CORE_INCLUDE_PATHS) -c $< -o $@ @$(CXX) -MM $(EXAMPLES_INCLUDE_PATHS) \ $(CORE_INCLUDE_PATHS) $< > $(@:.o=.d) @mv -f $(@:.o=.d) $(@:.o=.d.tmp) @@ -383,11 +249,11 @@ $(EXAMPLES_OBJ_DIR)/%.o: $(EXAMPLES_SRC_DIR)/%.cc # --- Linking --- # -$(EXAMPLES_BIN_DIR)/%: $(EXAMPLES_OBJ_DIR)/%.o $(CORE_OBJ) +$(EXAMPLES_BIN_DIR)/%: $(EXAMPLES_OBJ_DIR)/%.o $(CORE_LIB_DIR)/libtiledb.a @mkdir -p $(EXAMPLES_BIN_DIR) @echo "Creating $@" - @$(CXX) $(OPENMP_LIB_PATHS) $(OPENMP_LIB) $(MPI_LIB_PATHS) $(MPI_LIB) \ - -o $@ $^ $(ZLIB) $(OPENSSLLIB) + @$(CXX) -std=gnu++11 -o $@ $^ $(LIBRARY_PATHS) $(ZLIB) $(OPENSSLLIB) \ + -fopenmp # --- Cleaning --- # @@ -396,72 +262,9 @@ clean_examples: @rm -f $(EXAMPLES_OBJ_DEB_DIR)/* $(EXAMPLES_OBJ_REL_DIR)/* \ $(EXAMPLES_BIN_DEB_DIR)/* $(EXAMPLES_BIN_REL_DIR)/* - -###### -# LA # -###### - -# --- Compilation and dependency genration --- # - -# -include $(LA_OBJ:.o=.d) - -# $(LA_OBJ_DIR)/%.o: $(LA_SRC_DIR)/%.cc -# @test -d $(LA_OBJ_DIR) || mkdir -p $(LA_OBJ_DIR) -# @echo "Compiling $<" -# @$(CXX) $(LA_INCLUDE_PATHS) $(CORE_INCLUDE_PATHS) -c $< -o $@ -# @$(CXX) -MM $(CORE_INCLUDE_PATHS) $(LA_INCLUDE_PATHS) $< > $(@:.o=.d) -# @mv -f $(@:.o=.d) $(@:.o=.d.tmp) -# @sed 's|.*:|$@:|' < $(@:.o=.d.tmp) > $(@:.o=.d) -# @rm -f $(@:.o=.d.tmp) - -# --- Linking --- # - -# $(LA_BIN_DIR)/example_transpose: $(LA_OBJ) $(CORE_OBJ) -# @mkdir -p $(LA_BIN_DIR) -# @echo "Creating example_transpose" -# @$(CXX) $(OPENMP_LIB_PATHS) $(OPENMP_LIB) $(MPI_LIB_PATHS) $(MPI_LIB) \ -# -o $@ $^ - -# --- Cleaning --- # - -# clean_la: -# @echo 'Cleaning la' -# @rm -f $(LA_OBJ_DIR)/* $(LA_BIN_DIR)/* - -######## -# RVMA # -######## - -# --- Compilation and dependency genration --- # - -# -include $(RVMA_OBJ:.o=.d) - -# $(RVMA_OBJ_DIR)/%.o: $(RVMA_SRC_DIR)/%.c -# @test -d $(RVMA_OBJ_DIR) || mkdir -p $(RVMA_OBJ_DIR) -# @echo "Compiling $<" -# @$(CXX) $(RVMA_INCLUDE_PATHS) $(CORE_INCLUDE_PATHS) -c $< -o $@ -# @$(CXX) -MM $(CORE_INCLUDE_PATHS) $(RVMA_INCLUDE_PATHS) $< > $(@:.o=.d) -# @mv -f $(@:.o=.d) $(@:.o=.d.tmp) -# @sed 's|.*:|$@:|' < $(@:.o=.d.tmp) > $(@:.o=.d) -# @rm -f $(@:.o=.d.tmp) - -# --- Linking --- # - -# $(RVMA_BIN_DIR)/simple_test: $(RVMA_OBJ) $(CORE_OBJ) -# @mkdir -p $(RVMA_BIN_DIR) -# @echo "Creating simple_test" -# @$(CXX) $(OPENMP_LIB_PATHS) $(OPENMP_LIB) $(MPI_LIB_PATHS) $(MPI_LIB) \ -# -o $@ $^ - -# --- Cleaning --- # - -# clean_rvma: -# @echo 'Cleaning RVMA' -# @rm -f $(RVMA_OBJ_DIR)/* $(RVMA_BIN_DIR)/* - -################ -# TileDB Tests # -################ +# **************** # +# Test # +# **************** # # --- Compilation and dependency genration --- # @@ -470,7 +273,7 @@ clean_examples: $(TEST_OBJ_DIR)/%.o: $(TEST_SRC_DIR)/%.cc @mkdir -p $(dir $@) @echo "Compiling $<" - @$(CXX) $(TEST_INCLUDE_PATHS) -c $< -o $@ + @$(CXX) $(CPPFLAGS) $(TEST_INCLUDE_PATHS) -c $< -o $@ @$(CXX) -MM $(TEST_INCLUDE_PATHS) \ $(CORE_INCLUDE_PATHS) $< > $(@:.o=.d) @mv -f $(@:.o=.d) $(@:.o=.d.tmp) @@ -479,29 +282,26 @@ $(TEST_OBJ_DIR)/%.o: $(TEST_SRC_DIR)/%.cc # --- Linking --- # -$(TEST_BIN_DIR)/tiledb_test: $(TEST_OBJ) $(CORE_OBJ) +$(TEST_BIN_DIR)/tiledb_test: $(TEST_OBJ) $(CORE_LIB_DIR)/libtiledb.a @mkdir -p $(TEST_BIN_DIR) @echo "Creating test_cmd" - @$(CXX) $(LDFLAGS) $(OPENMP_LIB_PATHS) $(OPENMP_LIB) \ - $(MPI_LIB_PATHS) $(MPI_LIB) \ - -o $@ $^ $(ZLIB) $(OPENSSLLIB) -lgtest -lgtest_main + @$(CXX) -std=gnu++11 -o $@ $^ $(LIBRARY_PATHS) $(ZLIB) $(OPENSSLLIB) \ + $(GTESTLIB) -fopenmp # --- Cleaning --- # -clean_check: - @echo "Cleaning check" +clean_test: + @echo "Cleaning test" @rm -rf $(TEST_OBJ_DIR) $(TEST_BIN_DIR) -################################ -# Documentation (with Doxygen) # -################################ +# **************** # +# Documentation # +# **************** # -doxyfile.inc: $(CORE_INCLUDE) $(TILEDB_CMD_INCLUDE) $(LA_INCLUDE) \ - $(DOXYGEN_MAINPAGE) +doxyfile.inc: $(CORE_INCLUDE) $(DOXYGEN_MAINPAGE) @echo 'Creating Doxygen documentation' - @echo INPUT = $(DOXYGEN_DIR)/mainpage.dox $(CORE_INCLUDE) \ - $(TILEDB_CMD_INCLUDE) $(LA_INCLUDE) > doxyfile.inc + @echo INPUT = $(DOXYGEN_DIR)/mainpage.dox $(CORE_INCLUDE) > doxyfile.inc @echo FILE_PATTERNS = *.h >> doxyfile.inc @doxygen Doxyfile.mk > Doxyfile.log 2>&1 diff --git a/README.md b/README.md index 0ddc15eb..f84bbdb5 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,4 @@ -Introduction -============ +The TileDB documentation for users is hosted as +a Github wiki: https://github.com/Intel-HLS/TileDB/wiki -TileDB is a new array storage manager, particularly efficient for the case of -**sparse** arrays. It currently offers a small set of queries implemented -as stand-alone Linux programs. It also offers a high level C API that allows various -programming languages to manage persistent arrays by interfacing with TileDB as a library. -TileDB is envisioned to be used either as an HDF5-like distributed file system, -or as a full-fledged distributed array database. - -TileDB is currently under heavy development. Benchmark results, tutorials, -and research papers are under way. Stay tuned! - -Kick-start for users -==================== - -Run the following commands to get started, `packages.txt` contains some -packages required to build the documentation, you can replace `apt-get` with -your package manager of choice. - -```bash -git clone git@github.com:stavrospapadopoulos/TileDB.git -cd TileDB -cat packages.txt | xargs sudo apt-get -y install -make; make doc; -``` -The TileDB executable programs can be found in directory `tiledb_cmd/bin`, and -their corresponding documentation is in directory `manpages`, where you can -find either the man files inside subdirectory `manpages/man` or the respective -html in `manpages/html`. - -Perform the following steps to get familiar with the TileDB command line -interface: - -1. Define an array of your choice with `tiledb_define_array`. Read the - documentation, it is quite extensive and it provides examples. - -2. Generate a synthetic dataset for the array you defined using - `tiledb_generate_data`, always reading the documentation. Try a CSV file - first, so that you can see how it looks like in a text editor. - -3. Load the dataset into your array using `tiledb_load_csv`. Check what kind - of files TileDB creates in the workspace folder you provided. Every array is - essentially a folder of binary files with simple metadata, similar to HDF5. - -4. Now you can do other various things, such as export the dataset back to a - CSV file, choose a subarray, and make an update. Play with the queries, - consulting their documentation. - -Kick-start for developers -========================= - -Everything you need is in `core/include/capis/`. Given that you have run -`make doc`, you can see the documentation of each C API with detailed -guidelines on how to use it. Contact me if you require any particular -C API and I will try to develop it in a short time. - -Under construction -================== - -I will spend some time stabilizing the current code, heavily testing and -documenting it. At the same time, I have a list with C APIs I gathered -from you, so I will try to have everything ready soon. Finally, we are -preparing a paper with the specifics of the storage manager, as well -as tutorials for both users and developers. - -TroubleShooting -=============== - -* C++11 compile error: If the C++11 option is not recognized, try the following: - * Upgrade GCC. The version must be 4.3 or higher - * Use `-std=c++0x` instead - * If OS is CentOS or RedHat, use the `CXX = mpiicpc` instead of `mpicxx` - * Download latest Intel C/C++ compiler -* MPI-3 support is required, so make sure that the default MPI implements v3 of -the standard. +TileDB official website: http://istc-bigdata.org/tiledb diff --git a/README_GTEST.md b/README_GTEST.md deleted file mode 100644 index f3a259be..00000000 --- a/README_GTEST.md +++ /dev/null @@ -1,26 +0,0 @@ -INSTALL -======= - -* wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz -* tar xf release-1.7.0.tar.gz -* cd googletest-release-1.7.0 -* cmake -DBUILD_SHARED_LIBS=ON . -* make -* $ sudo cp -a include/gtest /usr/include -* $ sudo cp -a libgtest_main.so libgtest.so /usr/lib/ - -Check -===== - -$ sudo ldconfig -v | grep gtest - -Output should look like this: - -* libgtest.so.0 -> libgtest.so.0.0.0 -* libgtest_main.so.0 -> libgtest_main.so.0.0.0 - -Google Test framework is now ready to use. Just don't forget to link -your project against the library by setting -lgtest as linker flag -and optionally, if you did not write your own test mainroutine, -the explicit -lgtest_main flag. - diff --git a/core/include/array/array.h b/core/include/array/array.h index a417f2dd..39f499fa 100644 --- a/core/include/array/array.h +++ b/core/include/array/array.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/array/array_iterator.h b/core/include/array/array_iterator.h index 87f2f5b2..c2de5335 100644 --- a/core/include/array/array_iterator.h +++ b/core/include/array/array_iterator.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/array/array_read_state.h b/core/include/array/array_read_state.h index 35d22d76..cb6e729c 100644 --- a/core/include/array/array_read_state.h +++ b/core/include/array/array_read_state.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/array/array_schema.h b/core/include/array/array_schema.h index 60dd801d..465aa040 100644 --- a/core/include/array/array_schema.h +++ b/core/include/array/array_schema.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -661,7 +661,8 @@ class ArraySchema { * - TILEDB_INT64 * - TILEDB_FLOAT32 * - TILEDB_FLOAT64 - * - TILEDB_CHAR. + * - TILEDB_CHAR + * * The coordinate type can be one of the following: * - TILEDB_INT32 * - TILEDB_INT64 diff --git a/core/include/array/array_schema_c.h b/core/include/array/array_schema_c.h index 5e00d7b9..b178cc98 100644 --- a/core/include/array/array_schema_c.h +++ b/core/include/array/array_schema_c.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -107,7 +107,8 @@ typedef struct ArraySchemaC { * - TILEDB_INT64 * - TILEDB_FLOAT32 * - TILEDB_FLOAT64 - * - TILEDB_CHAR. + * - TILEDB_CHAR + * * The coordinate type can be one of the following: * - TILEDB_INT32 * - TILEDB_INT64 diff --git a/core/include/c_api/c_api.h b/core/include/c_api/c_api.h index 4ace4d60..3859f976 100755 --- a/core/include/c_api/c_api.h +++ b/core/include/c_api/c_api.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -86,7 +86,7 @@ TILEDB_EXPORT int tiledb_ctx_finalize(TileDB_CTX* tiledb_ctx); * Creates a new TileDB workspace. * * @param tiledb_ctx The TileDB context. - * @param workspace The directory to the workspace to be created in the file + * @param workspace The directory of the workspace to be created in the file * system. This directory should not be inside another TileDB workspace, * group, array or metadata directory. * @return TILEDB_OK for success and TILEDB_ERR for error. @@ -95,29 +95,6 @@ TILEDB_EXPORT int tiledb_workspace_create( const TileDB_CTX* tiledb_ctx, const char* workspace); -/** - * Lists all TileDB workspaces, copying their directory names in the input - * string buffers. - * - * @param tiledb_ctx The TileDB context. - * @param workspaces An array of strings that will store the listed workspaces. - * Note that this should be pre-allocated by the user. If the size of - * each string is smaller than the corresponding workspace path name, the - * function will probably segfault. It is a good idea to allocate to each - * workspace string TILEDB_NAME_MAX_LEN characters. - * @param workspace_num The number of allocated elements of the *workspaces* - * string array. After the function execution, this will hold the actual - * number of workspaces written in the *workspaces* string array. If the - * number of allocated elements is smaller than the number of existing - * TileDB workspaces, the function will return an error. - * @return TILEDB_OK for success and TILEDB_ERR for error. - */ -TILEDB_EXPORT int tiledb_ls_workspaces( - const TileDB_CTX* tiledb_ctx, - char** workspaces, - int* workspace_num); - - /* ********************************* */ @@ -179,9 +156,12 @@ typedef struct TileDB_ArraySchema { int* cell_val_num_; /** * The compression type for each attribute (plus one extra at the end for the - * coordinates. It can be one of the following: + * coordinates). It can be one of the following: * - TILEDB_NO_COMPRESSION - * - TILEDB_GZIP. + * - TILEDB_GZIP + * + * If it is *NULL*, then the default TILEDB_NO_COMPRESSION is used for all + * attributes. */ int* compression_; /** @@ -194,16 +174,15 @@ typedef struct TileDB_ArraySchema { /** The number of dimensions. */ int dim_num_; /** - * The array domain. It should contain one [lower, upper] pair per dimension. + * The array domain. It should contain one [low, high] pair per dimension. * The type of the values stored in this buffer should match the coordinates * type. */ void* domain_; /** * The tile extents. There should be one value for each dimension. The type of - * the values stored in this buffer should match the coordinates type. If it - * is NULL (applicable only to sparse arrays), then it means that the - * array has irregular tiles. + * the values stored in this buffer should match the coordinates type. It + * can be NULL only for sparse arrays. */ void* tile_extents_; /** @@ -219,7 +198,8 @@ typedef struct TileDB_ArraySchema { * - TILEDB_INT64 * - TILEDB_FLOAT32 * - TILEDB_FLOAT64 - * - TILEDB_CHAR. + * - TILEDB_CHAR + * * The coordinate type can be one of the following: * - TILEDB_INT32 * - TILEDB_INT64 @@ -230,25 +210,26 @@ typedef struct TileDB_ArraySchema { } TileDB_ArraySchema; /** - * Populates a TileDB array schema struct. + * Populates a TileDB array schema object. * + * @oaram tiledb_array_schema The array schema to be populated. * @param array_name The array name. * @param attributes The attribute names. * @param attribute_num The number of attributes. + * @param capacity The tile capacity. + * @param cell_order The cell order. + * @param cell_val_num The number of values per attribute per cell. + * @param compression The compression type for each attribute (plus an extra one + * in the end for the coordinates). + * @param dense Specifies if the array is dense (1) or sparse (0). * @param dimensions The dimension names. * @param dim_num The number of dimensions. - * @param dense Specifies if the array is dense (1) or sparse (0). * @param domain The array domain. * @param domain_len The length of *domain* in bytes. * @param tile_extents The tile extents. * @param tile_extents_len The length of *tile_extents* in bytes. - * @param types The attribute types (plus one in the end for the coordinates). - * @param cell_val_num The number of values per attribute per cell. - * @param cell_order The cell order. * @param tile_order The tile order. - * @param capacity The tile capacity. - * @param compression The compression type for each attribute (plus an extra one - * in the end for the coordinates). + * @param types The attribute types (plus one in the end for the coordinates). * @return TILEDB_OK for success and TILEDB_ERR for error. * @see TileDB_ArraySchema */ @@ -257,30 +238,30 @@ TILEDB_EXPORT int tiledb_array_set_schema( const char* array_name, const char** attributes, int attribute_num, + int64_t capacity, + int cell_order, + const int* cell_val_num, + const int* compression, + int dense, const char** dimensions, int dim_num, - int dense, const void* domain, size_t domain_len, const void* tile_extents, size_t tile_extents_len, - const int* types, - const int* cell_val_num, - int cell_order, int tile_order, - int64_t capacity, - const int* compression); + const int* types); /** * Creates a new TileDB array. * * @param tiledb_ctx The TileDB context. - * @param array_schema The array schema. + * @param tiledb_array_schema The array schema. * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_array_create( const TileDB_CTX* tiledb_ctx, - const TileDB_ArraySchema* array_schema); + const TileDB_ArraySchema* tiledb_array_schema); /** * Initializes a TileDB array. @@ -294,12 +275,15 @@ TILEDB_EXPORT int tiledb_array_create( * - TILEDB_ARRAY_WRITE_UNSORTED * - TILEDB_ARRAY_READ * @param subarray The subarray in which the array read/write will be - * constrained on. If it is NULL, then the subarray is set to the entire + * constrained on. It should be a sequence of [low, high] pairs (one + * pair per dimension), whose type should be the same as that of the + * coordinates. If it is NULL, then the subarray is set to the entire * array domain. For the case of writes, this is meaningful only for * dense arrays, and specifically dense writes. * @param attributes A subset of the array attributes the read/write will be - * constrained on. A NULL value indicates **all** attributes (including - * the coordinates in the case of sparse arrays). + * constrained on. Note that the coordinates have special attribute name + * TILEDB_COORDS. A NULL value indicates **all** attributes (including + * the coordinates as the last attribute in the case of sparse arrays). * @param attribute_num The number of the input attributes. If *attributes* is * NULL, then this should be set to 0. * @return TILEDB_OK on success, and TILEDB_ERR on error. @@ -316,12 +300,14 @@ TILEDB_EXPORT int tiledb_array_init( /** * Resets the subarray used upon initialization of the array. This is useful * when the array is used for reading, and the user wishes to change the - * query subarray without having to finalize and re-initialize the array - * with a different subarray. + * query subarray without having to finalize and re-initialize the array. * * @param tiledb_array The TileDB array. - * @param subarray The new subarray. Note that the type of the values in - * *subarray* should match the coordinates type in the array schema. + * @param subarray The new subarray. It should be a sequence of [low, high] + * pairs (one pair per dimension), whose type should be the same as that of + * the coordinates. If it is NULL, then the subarray is set to the entire + * array domain. For the case of writes, this is meaningful only for + * dense arrays, and specifically dense writes. * @return TILEDB_OK on success, and TILEDB_ERR on error. */ TILEDB_EXPORT int tiledb_array_reset_subarray( @@ -330,10 +316,11 @@ TILEDB_EXPORT int tiledb_array_reset_subarray( /** * Resets the attributes used upon initialization of the array. + * * @param tiledb_array The TileDB array. * @param attributes The new attributes to focus on. If it is NULL, then * all the attributes are used (including the coordinates in the case of - * sparse arrays). + * sparse arrays, or sparse writes to dense arrays). * @param attribute_num The number of the attributes. If *attributes* is NULL, * then this should be 0. * @return TILEDB_OK on success, and TILEDB_ERR on error. @@ -346,7 +333,6 @@ TILEDB_EXPORT int tiledb_array_reset_attributes( /** * Retrieves the schema of an already initialized array. * - * @param tiledb_ctx The TileDB context. * @param tiledb_array The TileDB array object (must already be initialized). * @param tiledb_array_schema The array schema to be retrieved. * @return TILEDB_OK for success and TILEDB_ERR for error. @@ -378,16 +364,13 @@ TILEDB_EXPORT int tiledb_array_free_schema( TileDB_ArraySchema* tiledb_array_schema); /** - * Performs a write operation in an array. The cell values are provided - * in a set of buffers (one per attribute specified upon initialization). - * Note that there must be a one-to-one correspondance between the cell - * values across the attribute buffers. - * + * Performs a write operation to an array. * The array must be initialized in one of the following write modes, - * each of which having a different behaviour: + * each of which has a different behaviour: * - TILEDB_ARRAY_WRITE: \n * In this mode, the cell values are provided in the buffers respecting - * the cell order on the disk. It is practically an **append** operation, + * the cell order on the disk (specified in the array schema). It is + * practically an **append** operation, * where the provided cell values are simply written at the end of * their corresponding attribute files. This mode leads to the best * performance. The user may invoke this function an arbitrary number @@ -400,21 +383,21 @@ TILEDB_EXPORT int tiledb_array_free_schema( * in this mode are given in an arbitrary, unsorted order (i.e., without * respecting how the cells must be stored on the disk according to the * array schema definition). Each invocation of this function internally - * sorts the cells and writes them to the disk on the proper order. In + * sorts the cells and writes them to the disk in the proper order. In * addition, each invocation creates a **new** fragment. Finally, the - * buffers in each invocation must be synced, i.e., they must have the - * same number of cell values across all attributes. + * buffers in each invocation must be synchronized, i.e., they must have + * the same number of cell values across all attributes. * - * @param tiledb_array The TileDB array. + * @param tiledb_array The TileDB array object (must be already initialized). * @param buffers An array of buffers, one for each attribute. These must be - * provided in the same order as the attributes specified in + * provided in the same order as the attribute order specified in * tiledb_array_init() or tiledb_array_reset_attributes(). The case of * variable-sized attributes is special. Instead of providing a single * buffer for such an attribute, **two** must be provided: the second * holds the variable-sized cell values, whereas the first holds the - * start offsets of each cell in the second buffer. - * @param buffer_sizes The sizes (in bytes) of the input buffers (there is - * a one-to-one correspondence). + * start offsets of each cell in the second buffer. + * @param buffer_sizes The sizes (in bytes) of the input buffers (there should + * be a one-to-one correspondence). * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_array_write( @@ -423,7 +406,7 @@ TILEDB_EXPORT int tiledb_array_write( const size_t* buffer_sizes); /** - * Performs a read operation in an array, which must be initialized with mode + * Performs a read operation on an array, which must be initialized with mode * TILEDB_ARRAY_READ. The function retrieves the result cells that lie inside * the subarray specified in tiledb_array_init() or * tiledb_array_reset_subarray(). The results are written in input buffers @@ -446,7 +429,7 @@ TILEDB_EXPORT int tiledb_array_write( * in the buffer. If a buffer cannot hold all results, the function will * still succeed, writing as much data as it can and turning on an overflow * flag which can be checked with function tiledb_array_overflow(). The - * next invocation will resume for the point the previous one stopped, + * next invocation will resume from the point the previous one stopped, * without inflicting a considerable performance penalty due to overflow. * @return TILEDB_OK for success and TILEDB_ERR for error. */ @@ -463,7 +446,8 @@ TILEDB_EXPORT int tiledb_array_read( * @param attribute_id The id of the attribute for which the overflow is * checked. This id corresponds to the position of the attribute name * placed in the *attributes* input of tiledb_array_init(), or - * tiledb_array_reset_attributes(). If *attributes* was NULL in the + * tiledb_array_reset_attributes() (the positions start from 0). + * If *attributes* was NULL in the * above functions, then the attribute id corresponds to the order * in which the attributes were defined in the array schema upon the * array creation. Note that, in that case, the extra coordinates @@ -484,7 +468,7 @@ TILEDB_EXPORT int tiledb_array_overflow( TILEDB_EXPORT int tiledb_array_consolidate(const TileDB_Array* tiledb_array); /** - * Finalizes a TileDB array, properly freeing the memory space. + * Finalizes a TileDB array, properly freeing its memory space. * * @param tiledb_array The array to be finalized. * @return TILEDB_OK on success, and TILEDB_ERR on error. @@ -505,11 +489,14 @@ typedef struct TileDB_ArrayIterator TileDB_ArrayIterator; * will allocate the appropriate memory space for the iterator. * @param array The directory of the array the iterator is initialized for. * @param subarray The subarray in which the array iterator will be - * constrained on. If it is NULL, then the subarray is set to the entire + * constrained on. It should be a sequence of [low, high] pairs (one + * pair per dimension), whose type should be the same as that of the + * coordinates. If it is NULL, then the subarray is set to the entire * array domain. * @param attributes A subset of the array attributes the iterator will be - * constrained on. A NULL value indicates **all** attributes (including - * the coordinates in the case of sparse arrays). + * constrained on. Note that the coordinates have special attribute name + * TILEDB_COORDS. A NULL value indicates **all** attributes (including + * the coordinates as the last attribute in the case of sparse arrays). * @param attribute_num The number of the input attributes. If *attributes* is * NULL, then this should be set to 0. * @param buffers This is an array of buffers similar to tiledb_array_read(). @@ -519,7 +506,7 @@ typedef struct TileDB_ArrayIterator TileDB_ArrayIterator; * cell values as possible in the user buffers. This gives the user the * flexibility to control the prefetching for optimizing performance * depending on the application. - * @param buffer_sizes The corresponding sizes (in bytes) of the allocated + * @param buffer_sizes The corresponding size (in bytes) of the allocated * memory space for *buffers*. The function will prefetch from the * disk as many cells as can fit in the buffers, whenever it finishes * iterating over the previously prefetched data. @@ -541,15 +528,19 @@ TILEDB_EXPORT int tiledb_array_iterator_init( * @param tiledb_array_it The TileDB array iterator. * @param attribute_id The id of the attribute for which the cell value * is retrieved. This id corresponds to the position of the attribute name - * placed in the *attributes* input of tiledb_array_iterator_init(). + * placed in the *attributes* input of tiledb_array_iterator_init() + * (the positions start from 0). * If *attributes* was NULL in the above function, then the attribute id * corresponds to the order in which the attributes were defined in the * array schema upon the array creation. Note that, in that case, the extra * coordinates attribute corresponds to the last extra attribute, i.e., * its id is *attribute_num*. * @param value The cell value to be retrieved. Note that its type is the - * same as that defined in the array schema. - * @param value_size The size (in bytes) of the retrieved value. + * same as that defined in the array schema for the corresponding attribute. + * Note also that the function essentially returns a pointer to this value + * in the internal buffers of the iterator. + * @param value_size The size (in bytes) of the retrieved value. Useful mainly + * for the case of variable-sized cells. * @return TILEDB_OK on success, and TILEDB_ERR on error. */ TILEDB_EXPORT int tiledb_array_iterator_get_value( @@ -616,9 +607,12 @@ typedef struct TileDB_MetadataSchema { int* cell_val_num_; /** * The compression type for each attribute (plus one extra at the end for the - * key. It can be one of the following: + * key). It can be one of the following: * - TILEDB_NO_COMPRESSION - * - TILEDB_GZIP. + * - TILEDB_GZIP + * + * If it is *NULL*, then the default TILEDB_NO_COMPRESSION is used for all + * attributes. */ int* compression_; /** @@ -637,16 +631,16 @@ typedef struct TileDB_MetadataSchema { typedef struct TileDB_Metadata TileDB_Metadata; /** - * Populates a TileDB metadata schema struct. + * Populates a TileDB metadata schema object. * * @param metadata_name The metadata name. * @param attributes The attribute names. * @param attribute_num The number of attributes. - * @param types The attribute types. - * @param cell_val_num The number of values per attribute per cell. * @param capacity The tile capacity. + * @param cell_val_num The number of values per attribute per cell. * @param compression The compression type for each attribute (plus an extra one * in the end for the key). + * @param types The attribute types. * @return TILEDB_OK for success and TILEDB_ERR for error. * @see TileDB_MetadataSchema */ @@ -655,10 +649,10 @@ TILEDB_EXPORT int tiledb_metadata_set_schema( const char* metadata_name, const char** attributes, int attribute_num, - const int* types, - const int* cell_val_num, int64_t capacity, - const int* compression); + const int* cell_val_num, + const int* compression, + const int* types); /** * Creates a new TileDB metadata object. @@ -682,8 +676,9 @@ TILEDB_EXPORT int tiledb_metadata_create( * - TILEDB_METADATA_WRITE * - TILEDB_METADATA_READ * @param attributes A subset of the metadata attributes the read/write will be - * constrained on. A NULL value indicates **all** attributes (including - * the key as an extra attribute in the end). + * constrained on. Note that the keys have a special attribute name + * called TILEDB_KEYS. A NULL value indicates **all** attributes (including + * the keys as an extra attribute in the end). * @param attribute_num The number of the input attributes. If *attributes* is * NULL, then this should be set to 0. * @return TILEDB_OK on success, and TILEDB_ERR on error. @@ -701,8 +696,7 @@ TILEDB_EXPORT int tiledb_metadata_init( * * @param tiledb_metadata The TileDB metadata. * @param attributes The new attributes to focus on. If it is NULL, then - * all the attributes are used (including the key as an extra attribute - * in the end). + * all the attributes are used. * @param attribute_num The number of the attributes. If *attributes* is NULL, * then this should be 0. * @return TILEDB_OK on success, and TILEDB_ERR on error. @@ -748,14 +742,12 @@ TILEDB_EXPORT int tiledb_metadata_free_schema( TileDB_MetadataSchema* tiledb_metadata_schema); /** - * Performs a write operation in metadata object. The values are provided - * in a set of buffers (one per attribute specified upon initialization). - * Note that there must be a one-to-one correspondance between the - * values across the attribute buffers. - * - * The metadata must be initialized with mode TILEDB_METADATA_WRITE. + * Performs a write operation to a metadata object. The metadata must be + * initialized with mode TILEDB_METADATA_WRITE. This function behave very + * similarly to tiledb_array_write() when the array is initialized with mode + * TILEDB_ARRAY_WRITE_UNSORTED. * - * @param tiledb_metadata The TileDB metadata. + * @param tiledb_metadata The TileDB metadata (must be already initialized). * @param keys The buffer holding the metadata keys. These keys must be * strings, serialized one after the other in the *keys* buffer. * @param keys_size The size (in bytes) of buffer *keys*. @@ -778,11 +770,11 @@ TILEDB_EXPORT int tiledb_metadata_write( const size_t* buffer_sizes); /** - * Performs a read operation in a metadata object, which must be initialized + * Performs a read operation on a metadata object, which must be initialized * with mode TILEDB_METADATA_READ. The read is performed on a single key. * * @param tiledb_metadata The TileDB metadata. - * @param key This is the query key, which must be a string. + * @param key The query key, which must be a string. * @param buffers An array of buffers, one for each attribute. These must be * provided in the same order as the attributes specified in * tiledb_metadata_init() or tiledb_metadata_reset_attributes(). The case of @@ -791,9 +783,11 @@ TILEDB_EXPORT int tiledb_metadata_write( * will hold the variable-sized values, whereas the first holds the * start offsets of each value in the second buffer. * @param buffer_sizes The sizes (in bytes) allocated by the user for the input - * buffers (there is a one-to-one correspondence). The function will attempt - * to write value corresponding to the key. If a buffer cannot hold the - * result, the function will still succeed, turning on an overflow + * buffers (there should be a one-to-one correspondence). The function will + * attempt to write the value corresponding to the key, and potentially + * alter the respective size in *buffer_sizes* to indicate the *useful* + * data written. If a buffer cannot + * hold the result, the function will still succeed, turning on an overflow * flag which can be checked with function tiledb_metadata_overflow(). * @return TILEDB_OK for success and TILEDB_ERR for error. */ @@ -811,12 +805,11 @@ TILEDB_EXPORT int tiledb_metadata_read( * @param attribute_id The id of the attribute for which the overflow is * checked. This id corresponds to the position of the attribute name * placed in the *attributes* input of tiledb_metadata_init(), or - * tiledb_metadata_reset_attributes(). If *attributes* was NULL in the + * tiledb_metadata_reset_attributes(). The positions start from 0. + * If *attributes* was NULL in the * above functions, then the attribute id corresponds to the order - * in which the attributes were defined in the array schema upon the - * array creation. Note that, in that case, the extra key - * attribute corresponds to the last extra attribute, i.e., its id - * is *attribute_num*. + * in which the attributes were defined in the metadata schema upon the + * metadata creation. * @return TILEDB_ERR for error, 1 for overflow, and 0 otherwise. */ TILEDB_EXPORT int tiledb_metadata_overflow( @@ -847,7 +840,7 @@ typedef struct TileDB_MetadataIterator TileDB_MetadataIterator; /** * Initializes a metadata iterator, potentially constraining it * on a subset of attributes. The values will be read in the order they are - * stored on the disk, maximing performance. + * stored on the disk (which is random), maximing performance. * * @param tiledb_ctx The TileDB context. * @param tiledb_metadata_it The TileDB metadata iterator to be created. The @@ -855,8 +848,8 @@ typedef struct TileDB_MetadataIterator TileDB_MetadataIterator; * @param metadata The directory of the metadata the iterator is initialized * for. * @param attributes A subset of the metadata attributes the iterator will be - * constrained on. A NULL value indicates **all** attributes (including - * the key as an extra attribute in the end). + * constrained on. Note that the keys have a special value called + * TILEDB_KEYS. A NULL value indicates **all** attributes. * @param attribute_num The number of the input attributes. If *attributes* is * NULL, then this should be set to 0. * @param buffers This is an array of buffers similar to tiledb_metadata_read(). @@ -885,16 +878,17 @@ TILEDB_EXPORT int tiledb_metadata_iterator_init( * Retrieves the current value for a particular attribute. * * @param tiledb_metadata_it The TileDB metadata iterator. - * @param attribute_id The id of the attribute for which the value - * is retrieved. This id corresponds to the position of the attribute name - * placed in the *attributes* input of tiledb_metadata_iterator_init(). - * If *attributes* was NULL in the above function, then the attribute id - * corresponds to the order in which the attributes were defined in the - * array schema upon the array creation. Note that, in that case, the extra - * key attribute corresponds to the last extra attribute, i.e., - * its id is *attribute_num*. + * @param attribute_id The id of the attribute for which the overflow is + * checked. This id corresponds to the position of the attribute name + * placed in the *attributes* input of tiledb_metadata_init(), or + * tiledb_metadata_reset_attributes(). The positions start from 0. + * If *attributes* was NULL in the + * above functions, then the attribute id corresponds to the order + * in which the attributes were defined in the metadata schema upon the + * metadata creation. * @param value The value to be retrieved. Note that its type is the - * same as that defined in the metadata schema. + * same as that defined in the metadata schema. Note also that the function + * returns a pointer to this value in the internal buffers of the iterator. * @param value_size The size (in bytes) of the retrieved value. * @return TILEDB_OK on success, and TILEDB_ERR on error. */ @@ -936,7 +930,7 @@ TILEDB_EXPORT int tiledb_metadata_iterator_finalize( /* ********************************* */ -/* MISC */ +/* DIRECTORY MANAGEMENT */ /* ********************************* */ /** @@ -945,7 +939,7 @@ TILEDB_EXPORT int tiledb_metadata_iterator_finalize( * function, but it will be empty (i.e., as if it was just created). * * @param tiledb_ctx The TileDB context. - * @param dir The directory to be cleared. + * @param dir The TileDB directory to be cleared. * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_clear( @@ -956,7 +950,7 @@ TILEDB_EXPORT int tiledb_clear( * Deletes a TileDB directory (workspace, group, array, or metadata) entirely. * * @param tiledb_ctx The TileDB context. - * @param dir The directory to be deleted. + * @param dir The TileDB directory to be deleted. * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_delete( @@ -967,8 +961,8 @@ TILEDB_EXPORT int tiledb_delete( * Moves a TileDB directory (workspace, group, array or metadata). * * @param tiledb_ctx The TileDB context. - * @param old_dir The old directory. - * @param new_dir The new directory. + * @param old_dir The old TileDB directory. + * @param new_dir The new TileDB directory. * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_move( @@ -977,24 +971,49 @@ TILEDB_EXPORT int tiledb_move( const char* new_dir); /** - * Lists all the TileDB objects in a directory, copying them into the input - * buffers. + * Lists all TileDB workspaces, copying their directory names in the input + * string buffers. + * + * @param tiledb_ctx The TileDB context. + * @param workspaces An array of strings that will store the listed workspaces. + * Note that this should be pre-allocated by the user. If the size of + * each string is smaller than the corresponding workspace path name, the + * function will probably segfault. It is a good idea to allocate to each + * workspace string TILEDB_NAME_MAX_LEN characters. + * @param workspace_num The number of allocated elements of the *workspaces* + * string array. After the function execution, this will hold the actual + * number of workspaces written in the *workspaces* string array. If the + * number of allocated elements is smaller than the number of existing + * TileDB workspaces, the function will return an error. + * @return TILEDB_OK for success and TILEDB_ERR for error. + */ +TILEDB_EXPORT int tiledb_ls_workspaces( + const TileDB_CTX* tiledb_ctx, + char** workspaces, + int* workspace_num); + + +/** + * Lists all the TileDB objects in a directory, copying their names into the + * input string buffers. * * @param tiledb_ctx The TileDB context. * @param parent_dir The parent directory of the TileDB objects to be listed. * @param dirs An array of strings that will store the listed TileDB objects. * Note that the user is responsible for allocating the appropriate memory - * space for this array of strings. A good idea for each string length is - * to set is to TILEDB_NAME_MAX_LEN. - * @param dir_types The types of the corresponding TileDB objects, which can - * be the following (they are self-explanatory): + * space for this array of strings. A good idea is to allocate for each + * string TILEDB_NAME_MAX_LEN characters. + * @param dir_types The types of the corresponding TileDB objects in *dirs*, + * which can be the following: * - TILEDB_WORKSPACE * - TILEDB_GROUP * - TILEDB_ARRAY * - TILEDB_METADATA * @param dir_num The number of elements allocated by the user for *dirs*. After * the function terminates, this will hold the actual number of TileDB - * objects that were stored in *dirs*. + * objects that were stored in *dirs*. If the number of + * allocated elements is smaller than the number of existing TileDB objects + * in the parent directory, the function will return an error. * @return TILEDB_OK for success and TILEDB_ERR for error. */ TILEDB_EXPORT int tiledb_ls( diff --git a/core/include/c_api/constants.h b/core/include/c_api/constants.h index c7b4c72f..145b52fa 100644 --- a/core/include/c_api/constants.h +++ b/core/include/c_api/constants.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -80,7 +80,7 @@ #define TILEDB_CONSOLIDATION_BUFFER_SIZE 10000000 // ~10 MB /**@{*/ -/** Special cell value. */ +/** Special empty cell value. */ #define TILEDB_EMPTY_INT32 INT_MAX #define TILEDB_EMPTY_INT64 LLONG_MAX #define TILEDB_EMPTY_FLOAT32 FLT_MAX @@ -132,7 +132,7 @@ #define TILEDB_GZIP_CHUNK_SIZE 131072 // 128KB /**@{*/ -/** Special file name. */ +/** Special TileDB file name. */ #define TILEDB_ARRAY_SCHEMA_FILENAME "__array_schema.tdb" #define TILEDB_METADATA_SCHEMA_FILENAME "__metadata_schema.tdb" #define TILEDB_BOOK_KEEPING_FILENAME "__book_keeping" @@ -142,7 +142,7 @@ /**@}*/ /**@{*/ -/** Sizes of buffers used for sorting. */ +/** Size of buffer used for sorting. */ #define TILEDB_SORTED_BUFFER_SIZE 10000000 // ~10MB #define TILEDB_SORTED_BUFFER_VAR_SIZE 10000000 // ~10MB /**@}*/ diff --git a/core/include/fragment/book_keeping.h b/core/include/fragment/book_keeping.h index 00d87b71..9ef652a2 100644 --- a/core/include/fragment/book_keeping.h +++ b/core/include/fragment/book_keeping.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -233,10 +233,13 @@ class BookKeeping { std::vector > tile_offsets_; /** * The variable tile offsets in their corresponding attribute files. - * Meaningful only when there is compression. + * Meaningful only for variable-sized tiles. */ std::vector > tile_var_offsets_; - /** The sizes of the variable tiles. */ + /* + * The sizes of the uncompressed variable tiles. + * Meaningful only when there is compression for variable tiles. + */ std::vector > tile_var_sizes_; diff --git a/core/include/fragment/fragment.h b/core/include/fragment/fragment.h index ee350bbb..4e28c8bf 100644 --- a/core/include/fragment/fragment.h +++ b/core/include/fragment/fragment.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/fragment/read_state.h b/core/include/fragment/read_state.h index b9a51ee7..753430ae 100644 --- a/core/include/fragment/read_state.h +++ b/core/include/fragment/read_state.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/fragment/write_state.h b/core/include/fragment/write_state.h index 992a002d..0f4d62d3 100644 --- a/core/include/fragment/write_state.h +++ b/core/include/fragment/write_state.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/metadata/metadata.h b/core/include/metadata/metadata.h index 67fa7ef2..8baf1f50 100644 --- a/core/include/metadata/metadata.h +++ b/core/include/metadata/metadata.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/metadata/metadata_iterator.h b/core/include/metadata/metadata_iterator.h index 5867a912..4ba5b972 100644 --- a/core/include/metadata/metadata_iterator.h +++ b/core/include/metadata/metadata_iterator.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/metadata/metadata_schema_c.h b/core/include/metadata/metadata_schema_c.h index cfe175df..fb5d67e0 100644 --- a/core/include/metadata/metadata_schema_c.h +++ b/core/include/metadata/metadata_schema_c.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/misc/hilbert_curve.h b/core/include/misc/hilbert_curve.h index 50bb914a..ac723090 100755 --- a/core/include/misc/hilbert_curve.h +++ b/core/include/misc/hilbert_curve.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/misc/utils.h b/core/include/misc/utils.h index e630bb4f..0393be36 100644 --- a/core/include/misc/utils.h +++ b/core/include/misc/utils.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/include/storage_manager/storage_manager.h b/core/include/storage_manager/storage_manager.h index 4643299e..8a0f5822 100755 --- a/core/include/storage_manager/storage_manager.h +++ b/core/include/storage_manager/storage_manager.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/src/array/array.cc b/core/src/array/array.cc index 308f8dd0..a66271c5 100644 --- a/core/src/array/array.cc +++ b/core/src/array/array.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -185,6 +185,10 @@ int Array::consolidate() { finalize(); init(array_schema_, TILEDB_ARRAY_READ, NULL, 0, NULL); + // Trivial case + if(fragments_.size() == 1) + return TILEDB_AS_OK; + // Create new fragment Fragment* new_fragment = new Fragment(this); if(new_fragment->init(new_fragment_name(), TILEDB_ARRAY_WRITE, subarray_) != @@ -327,7 +331,9 @@ int Array::init( std::vector attributes_vec; if(attributes == NULL) { // Default: all attributes attributes_vec = array_schema->attributes(); - if(array_schema->dense()) // Remove coordinates attribute for dense arrays + if(array_schema->dense() && mode != TILEDB_ARRAY_WRITE_UNSORTED) + // Remove coordinates attribute for dense arrays, + // unless in TILEDB_WRITE_UNSORTED mode attributes_vec.pop_back(); } else { // Custom attributes for(int i=0; i(buffers_[buffer_i+1]) + offset; if(pos < cell_num_[attribute_id] - 1) *value_size = static_cast(buffers_[buffer_i])[pos+1] - offset; - else { + else *value_size = buffer_sizes_[buffer_i+1] - offset; - } } // Success @@ -179,7 +178,7 @@ int ArrayIterator::init( // Update cell num if(cell_sizes_[i] == TILEDB_VAR_SIZE) // VARIABLE - cell_num_[i] = buffer_sizes[buffer_i_[i]] / sizeof(size_t); + cell_num_[i] = buffer_sizes[buffer_i_[i]] / TILEDB_CELL_VAR_OFFSET_SIZE; else // FIXED cell_num_[i] = buffer_sizes[buffer_i_[i]] / cell_sizes_[i]; } diff --git a/core/src/array/array_read_state.cc b/core/src/array/array_read_state.cc index 9ee65c5d..0419b233 100644 --- a/core/src/array/array_read_state.cc +++ b/core/src/array/array_read_state.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -719,7 +719,6 @@ int ArrayReadState::get_next_fragment_cell_ranges_dense() { fragment_cell_pos_ranges) != TILEDB_ARS_OK) return TILEDB_ARS_ERR; - // Insert cell pos ranges in the state fragment_cell_pos_ranges_vec_.push_back(fragment_cell_pos_ranges); @@ -865,12 +864,7 @@ void ArrayReadState::get_next_overlapping_tiles_sparse() { } } else { // Get the next overlapping tile for the appropriate fragments - done_ = true; for(int i=0; i(fragment_bounding_coords_[i]); @@ -884,10 +878,21 @@ void ArrayReadState::get_next_overlapping_tiles_sparse() { fragment_read_states_[i]->get_bounding_coords( fragment_bounding_coords_[i]); } else { + if(fragment_bounding_coords_[i]) + free(fragment_bounding_coords_[i]); fragment_bounding_coords_[i] = NULL; } } } + + // Check if done + done_ = true; + for(int i=0; i(trimmed_top.second); memcpy(trimmed_top_range, &popped_range[dim_num], coords_size); memcpy(&trimmed_top_range[dim_num], &top_range[dim_num], coords_size); - array_schema->get_next_cell_coords( - tile_domain, - trimmed_top_range); - pq.push(trimmed_top); + if(fragment_read_states_[top_fragment_i]->dense()) { + array_schema->get_next_cell_coords( // TOP IS DENSE + tile_domain, + trimmed_top_range); + pq.push(trimmed_top); + } else { // TOP IS SPARSE + bool coords_retrieved; + if(fragment_read_states_[top_fragment_i]->get_coords_after( + &popped_range[dim_num], + trimmed_top_range, + coords_retrieved)) { + free(trimmed_top_range); + return TILEDB_ARS_ERR; + } + if(coords_retrieved) + pq.push(trimmed_top); + else + free(trimmed_top_range); + } } else { // Simply discard top and get a new one free(top.second); } diff --git a/core/src/array/array_schema.cc b/core/src/array/array_schema.cc index 95e426a3..fc6868ae 100644 --- a/core/src/array/array_schema.cc +++ b/core/src/array/array_schema.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -1021,7 +1021,7 @@ int ArraySchema::init(const MetadataSchemaC* metadata_schema_c) { // Set compression int* compression = (int*) malloc((metadata_schema_c->attribute_num_+2)*sizeof(int)); - if(metadata_schema_c->cell_val_num_ == NULL) { + if(metadata_schema_c->compression_ == NULL) { for(int i=0; iattribute_num_+1; ++i) compression[i] = TILEDB_NO_COMPRESSION; } else { @@ -1370,6 +1370,7 @@ int ArraySchema::cell_order_cmp(const T* coords_a, const T* coords_b) const { // Check hilbert ids int64_t id_a = hilbert_id(coords_a); int64_t id_b = hilbert_id(coords_b); + if(id_a < id_b) return -1; else if(id_a > id_b) @@ -1509,7 +1510,7 @@ int64_t ArraySchema::get_tile_pos( const T* domain, const T* tile_coords) const { // Sanity check - assert(dense_); + assert(tile_extents_); // Invoke the proper function based on the tile order if(tile_order_ == TILEDB_ROW_MAJOR) @@ -1792,17 +1793,6 @@ size_t ArraySchema::compute_type_size(int i) const { return sizeof(double); } - - - - - - - - - - - template int64_t ArraySchema::get_cell_pos_col(const T* coords) const { // For easy reference @@ -1822,9 +1812,8 @@ int64_t ArraySchema::get_cell_pos_col(const T* coords) const { T coords_norm; // Normalized coordinates inside the tile int64_t pos = 0; for(int i=0; istorage_manager_->ls_workspaces( - workspaces, - *workspace_num) != TILEDB_SM_OK) - return TILEDB_ERR; - else - return TILEDB_OK; -} - @@ -217,19 +200,19 @@ int tiledb_array_set_schema( const char* array_name, const char** attributes, int attribute_num, + int64_t capacity, + int cell_order, + const int* cell_val_num, + const int* compression, + int dense, const char** dimensions, int dim_num, - int dense, const void* domain, size_t domain_len, const void* tile_extents, size_t tile_extents_len, - const int* types, - const int* cell_val_num, - int cell_order, int tile_order, - int64_t capacity, - const int* compression) { + const int* types) { // Sanity check if(tiledb_array_schema == NULL) { PRINT_ERROR("Invalid array schema pointer"); @@ -722,10 +705,10 @@ int tiledb_metadata_set_schema( const char* metadata_name, const char** attributes, int attribute_num, - const int* types, - const int* cell_val_num, int64_t capacity, - const int* compression) { + const int* cell_val_num, + const int* compression, + const int* types) { // Sanity check if(tiledb_metadata_schema == NULL) { PRINT_ERROR("Invalid metadata schema pointer"); @@ -1131,7 +1114,7 @@ int tiledb_metadata_iterator_finalize( /* ****************************** */ -/* MISC */ +/* DIRECTORY MANAGEMENT */ /* ****************************** */ int tiledb_clear( @@ -1177,6 +1160,23 @@ int tiledb_move( return TILEDB_OK; } +int tiledb_ls_workspaces( + const TileDB_CTX* tiledb_ctx, + char** workspaces, + int* workspace_num) { + // Sanity check + if(!sanity_check(tiledb_ctx)) + return TILEDB_ERR; + + // List workspaces + if(tiledb_ctx->storage_manager_->ls_workspaces( + workspaces, + *workspace_num) != TILEDB_SM_OK) + return TILEDB_ERR; + else + return TILEDB_OK; +} + int tiledb_ls( const TileDB_CTX* tiledb_ctx, const char* parent_dir, diff --git a/core/src/fragment/book_keeping.cc b/core/src/fragment/book_keeping.cc index 197f99c6..e1838582 100644 --- a/core/src/fragment/book_keeping.cc +++ b/core/src/fragment/book_keeping.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -559,8 +559,8 @@ int BookKeeping::flush_tile_offsets(gzFile fd) const { continue; // Write tile offsets - if(gzwrite(fd, &tile_offsets_[i][0], tile_offsets_num * sizeof(size_t)) != - tile_offsets_num * sizeof(size_t)) { + if(gzwrite(fd, &tile_offsets_[i][0], tile_offsets_num * sizeof(off_t)) != + tile_offsets_num * sizeof(off_t)) { PRINT_ERROR("Cannot finalize book-keeping; Writing tile offsets failed"); return TILEDB_BK_ERR; } @@ -601,8 +601,8 @@ int BookKeeping::flush_tile_var_offsets(gzFile fd) const { if(gzwrite( fd, &tile_var_offsets_[i][0], - tile_var_offsets_num * sizeof(size_t)) != - tile_var_offsets_num * sizeof(size_t)) { + tile_var_offsets_num * sizeof(off_t)) != + tile_var_offsets_num * sizeof(off_t)) { PRINT_ERROR("Cannot finalize book-keeping; Writing variable tile " "offsets failed"); return TILEDB_BK_ERR; @@ -807,8 +807,8 @@ int BookKeeping::load_tile_offsets(gzFile fd) { // Get tile offsets tile_offsets_[i].resize(tile_offsets_num); - if(gzread(fd, &tile_offsets_[i][0], tile_offsets_num * sizeof(size_t)) != - tile_offsets_num * sizeof(size_t)) { + if(gzread(fd, &tile_offsets_[i][0], tile_offsets_num * sizeof(off_t)) != + tile_offsets_num * sizeof(off_t)) { PRINT_ERROR("Cannot load book-keeping; Reading tile offsets failed"); return TILEDB_BK_ERR; } @@ -852,8 +852,8 @@ int BookKeeping::load_tile_var_offsets(gzFile fd) { if(gzread( fd, &tile_var_offsets_[i][0], - tile_var_offsets_num * sizeof(size_t)) != - tile_var_offsets_num * sizeof(size_t)) { + tile_var_offsets_num * sizeof(off_t)) != + tile_var_offsets_num * sizeof(off_t)) { PRINT_ERROR("Cannot load book-keeping; Reading variable tile " "offsets failed"); return TILEDB_BK_ERR; diff --git a/core/src/fragment/fragment.cc b/core/src/fragment/fragment.cc index 40d68076..7adf786a 100644 --- a/core/src/fragment/fragment.cc +++ b/core/src/fragment/fragment.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/src/fragment/read_state.cc b/core/src/fragment/read_state.cc index 07e46082..056c7c87 100644 --- a/core/src/fragment/read_state.cc +++ b/core/src/fragment/read_state.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -164,9 +164,9 @@ ReadState::~ReadState() { PRINT_WARNING("Problem in finalizing ReadState; Memory unmap error"); } - for(int i=0; icell_order(); size_t cell_range_size = 2*array_schema->coords_size(); const T* search_tile_overlap_subarray = - static_cast(search_tile_overlap_subarray); + static_cast(search_tile_overlap_subarray_); FragmentInfo fragment_info = FragmentInfo(fragment_i, search_tile_pos_); // Contiguous cells, single cell range if(search_tile_overlap_ == 1 || - search_tile_overlap_ == 2) { + search_tile_overlap_ == 3) { void* cell_range = malloc(cell_range_size); T* cell_range_T = static_cast(cell_range); for(int i=0; i @@ -831,8 +842,9 @@ void ReadState::get_next_overlapping_tile_dense(const T* tile_coords) { // Find the search tile position T* tile_coords_norm = new T[dim_num]; for(int i=0; iget_tile_pos(domain, tile_coords); + tile_coords_norm[i] = + tile_coords[i] - (domain[2*i]-array_domain[2*i]) / tile_extents[i]; + search_tile_pos_ = array_schema->get_tile_pos(domain, tile_coords_norm); delete [] tile_coords_norm; // Compute overlap of the query subarray with tile @@ -1044,10 +1056,13 @@ void ReadState::compute_bytes_to_copy( // If bytes do not fit in variable buffer, we need to adjust if(bytes_var_to_copy > buffer_var_free_space) { // Perform binary search - int64_t min = start_cell_pos; + int64_t min = start_cell_pos + 1; int64_t max = end_cell_pos; int64_t med; - while(min < max) { + // Invariants: + // (tile[min-1] - tile[start_cell_pos]) < buffer_var_free_space AND + // (tile[max+1] - tile[start_cell_pos]) > buffer_var_free_space + while(min <= max) { med = min + ((max - min) / 2); // Calculate variable bytes to copy @@ -1063,10 +1078,13 @@ void ReadState::compute_bytes_to_copy( } // Determine the end position of the range - if(min == max) - end_cell_pos = min - 1; - else - end_cell_pos = med - 1; + int64_t tmp_end = -1; + if(min > max) + tmp_end = min - 2 ; + else + tmp_end = med - 1; + + end_cell_pos = std::max(tmp_end, start_cell_pos-1); // Update variable bytes to copy bytes_var_to_copy = tile[end_cell_pos + 1] - tile[start_cell_pos]; @@ -1121,6 +1139,7 @@ void ReadState::compute_tile_search_range() { if(tile_search_range_[0] == -1 || tile_search_range_[1] == -1) done_ = true; + } template @@ -1133,12 +1152,12 @@ void ReadState::compute_tile_search_range_col_or_row() { const std::vector& bounding_coords = book_keeping_->bounding_coords(); - // Calculate range coordinates + // Calculate subarray coordinates T* subarray_min_coords = new T[dim_num]; T* subarray_max_coords = new T[dim_num]; for(int i=0; itile_size(attribute_id_real); int64_t cell_num = book_keeping_->cell_num(tile_i); size_t tile_size = cell_num * cell_size; - const std::vector >& tile_offsets = book_keeping_->tile_offsets(); int64_t tile_num = book_keeping_->tile_num(); @@ -1601,36 +1619,40 @@ int ReadState::get_tile_from_disk_var_cmp_gzip( // Get size of decompressed tile size_t tile_var_size = book_keeping_->tile_var_sizes()[attribute_id][tile_i]; - // Potentially allocate space for buffer - if(tiles_var_[attribute_id] == NULL) { - tiles_var_[attribute_id] = malloc(tile_var_size); - tiles_var_allocated_size_[attribute_id] = tile_var_size; - } + //Non-empty tile, decompress + if(tile_var_size > 0u) { + // Potentially allocate space for buffer + if(tiles_var_[attribute_id] == NULL) { + tiles_var_[attribute_id] = malloc(tile_var_size); + tiles_var_allocated_size_[attribute_id] = tile_var_size; + } - // Potentially expand buffer - if(tile_var_size > tiles_var_allocated_size_[attribute_id]) { - tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tile_var_size); - tiles_var_allocated_size_[attribute_id] = tile_var_size; - } + // Potentially expand buffer + if(tile_var_size > tiles_var_allocated_size_[attribute_id]) { + tiles_var_[attribute_id] = + realloc(tiles_var_[attribute_id], tile_var_size); + tiles_var_allocated_size_[attribute_id] = tile_var_size; + } - // Read tile from file - if(READ_TILE_FROM_FILE_VAR_CMP_GZIP( - attribute_id, - file_offset, - tile_compressed_size) != TILEDB_RS_OK) - return TILEDB_RS_ERR; + // Read tile from file + if(READ_TILE_FROM_FILE_VAR_CMP_GZIP( + attribute_id, + file_offset, + tile_compressed_size) != TILEDB_RS_OK) + return TILEDB_RS_ERR; - // Decompress tile - if(gunzip( - static_cast(tile_compressed_), - tile_compressed_size, - static_cast(tiles_var_[attribute_id]), - tile_var_size, - gunzip_out_size) != TILEDB_UT_OK) - return TILEDB_RS_ERR; + // Decompress tile + if(gunzip( + static_cast(tile_compressed_), + tile_compressed_size, + static_cast(tiles_var_[attribute_id]), + tile_var_size, + gunzip_out_size) != TILEDB_UT_OK) + return TILEDB_RS_ERR; - // Sanity check - assert(gunzip_out_size == tile_var_size); + // Sanity check + assert(gunzip_out_size == tile_var_size); + } // Set the variable tile size tiles_var_sizes_[attribute_id] = tile_var_size; @@ -2066,19 +2088,25 @@ int ReadState::read_tile_from_file_with_mmap_var_cmp_gzip( } // Map - map_addr_compressed_ = mmap( - map_addr_compressed_, - new_length, - PROT_READ, - MAP_SHARED, - fd, - start_offset); - if(map_addr_compressed_ == MAP_FAILED) { - map_addr_compressed_ = NULL; - map_addr_compressed_length_ = 0; - tile_compressed_ = NULL; - PRINT_ERROR("Cannot read tile from file; Memory map error"); - return TILEDB_RS_ERR; + // new_length could be 0 for variable length fields, mmap will fail + // if new_length == 0 + if(new_length > 0u) { + map_addr_compressed_ = mmap( + map_addr_compressed_, + new_length, + PROT_READ, + MAP_SHARED, + fd, + start_offset); + if(map_addr_compressed_ == MAP_FAILED) { + map_addr_compressed_ = NULL; + map_addr_compressed_length_ = 0; + tile_compressed_ = NULL; + PRINT_ERROR("Cannot read tile from file; Memory map error"); + return TILEDB_RS_ERR; + } + } else { + map_addr_var_[attribute_id] = 0; } map_addr_compressed_length_ = new_length; @@ -2137,20 +2165,26 @@ int ReadState::read_tile_from_file_with_mmap_var_cmp_none( } // Map - map_addr_var_[attribute_id] = mmap( - map_addr_var_[attribute_id], - new_length, - PROT_READ, - MAP_SHARED, - fd, - start_offset); - if(map_addr_var_[attribute_id] == MAP_FAILED) { - map_addr_var_[attribute_id] = NULL; - map_addr_var_lengths_[attribute_id] = 0; - tiles_var_[attribute_id] = NULL; - tiles_var_sizes_[attribute_id] = 0; - PRINT_ERROR("Cannot read tile from file; Memory map error"); - return TILEDB_RS_ERR; + // new_length could be 0 for variable length fields, mmap will fail + // if new_length == 0 + if(new_length > 0u) { + map_addr_var_[attribute_id] = mmap( + map_addr_var_[attribute_id], + new_length, + PROT_READ, + MAP_SHARED, + fd, + start_offset); + if(map_addr_var_[attribute_id] == MAP_FAILED) { + map_addr_var_[attribute_id] = NULL; + map_addr_var_lengths_[attribute_id] = 0; + tiles_var_[attribute_id] = NULL; + tiles_var_sizes_[attribute_id] = 0; + PRINT_ERROR("Cannot read tile from file; Memory map error"); + return TILEDB_RS_ERR; + } + } else { + map_addr_var_[attribute_id] = 0; } map_addr_var_lengths_[attribute_id] = new_length; diff --git a/core/src/fragment/write_state.cc b/core/src/fragment/write_state.cc index 49ef2adc..fb578a0d 100644 --- a/core/src/fragment/write_state.cc +++ b/core/src/fragment/write_state.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -185,6 +185,25 @@ int WriteState::write(const void** buffers, const size_t* buffer_sizes) { if(!is_dir(fragment_name)) { if(create_dir(fragment_name) != TILEDB_UT_OK) return TILEDB_WS_ERR; + // For variable length attributes, ensure an empty file exists + // This is because if the current fragment contains no valid values for this + // attribute, then the file never gets created. This messes up querying + // functions + const ArraySchema* array_schema = fragment_->array()->array_schema(); + const std::vector& attribute_ids = fragment_->array()->attribute_ids(); + const std::string file_prefix = fragment_->fragment_name() + "/"; + std::string filename = ""; + // Go over var length attributes + for(int i=0; ivar_size(attribute_ids[i])) { + filename = file_prefix + array_schema->attribute(attribute_ids[i]) + + "_var" + TILEDB_FILE_SUFFIX; + FILE* fptr = fopen(filename.c_str(), "a"); + if(fptr == 0) + return TILEDB_WS_ERR; + fclose(fptr); + } + } } // Dispatch the proper write command @@ -241,7 +260,7 @@ int WriteState::compress_and_write_tile(int attribute_id) { // Compress tile ssize_t tile_compressed_size = gzip(tile, tile_size, tile_compressed, tile_compressed_allocated_size_); - if(tile_compressed_size != TILEDB_UT_OK) + if(tile_compressed_size == static_cast(TILEDB_UT_ERR)) return TILEDB_WS_ERR; // Get the attribute file name @@ -270,8 +289,12 @@ int WriteState::compress_and_write_tile_var(int attribute_id) { size_t tile_size = tiles_var_offsets_[attribute_id]; // Trivial case - No in-memory tile - if(tile_size == 0) + if(tile_size == 0) { + // Append offset to book-keeping + book_keeping_->append_tile_var_offset(attribute_id, 0u); + book_keeping_->append_tile_var_size(attribute_id, 0u); return TILEDB_WS_OK; + } // Allocate space to store the compressed tile if(tile_compressed_ == NULL) { @@ -579,6 +602,10 @@ int WriteState::write_dense_attr( int attribute_id, const void* buffer, size_t buffer_size) { + // Trivial case + if(buffer_size == 0) + return TILEDB_WS_OK; + // For easy reference const ArraySchema* array_schema = fragment_->array()->array_schema(); int compression = array_schema->compression(attribute_id); @@ -665,7 +692,7 @@ int WriteState::write_dense_attr_cmp_gzip( // Partially fill the (new) current tile bytes_to_fill = buffer_size - buffer_offset; if(bytes_to_fill != 0) { - memcpy(tile, buffer_c + buffer_offset, bytes_to_fill); + memcpy(tile + tile_offset, buffer_c + buffer_offset, bytes_to_fill); buffer_offset += bytes_to_fill; assert(buffer_offset == buffer_size); tile_offset += bytes_to_fill; @@ -681,6 +708,10 @@ int WriteState::write_dense_attr_var( size_t buffer_size, const void* buffer_var, size_t buffer_var_size) { + // Trivial case + if(buffer_size == 0) + return TILEDB_WS_OK; + // For easy reference const ArraySchema* array_schema = fragment_->array()->array_schema(); int compression = array_schema->compression(attribute_id); @@ -813,8 +844,10 @@ int WriteState::write_dense_attr_var_cmp_gzip( tile_offset += bytes_to_fill; // Compress current tile and write it to disk - if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_offset = 0; @@ -825,6 +858,8 @@ int WriteState::write_dense_attr_var_cmp_gzip( tiles_var_sizes_[attribute_id] = tile_var_offset + bytes_to_fill_var; tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); } // Fill up current variable tile @@ -836,9 +871,10 @@ int WriteState::write_dense_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; // Compress current tile and write it to disk - if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; - + } // Update local tile buffer offset tile_var_offset = 0; } @@ -851,8 +887,10 @@ int WriteState::write_dense_attr_var_cmp_gzip( tile_offset += tile_size; // Compress and write current tile - if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_offset = 0; @@ -871,6 +909,8 @@ int WriteState::write_dense_attr_var_cmp_gzip( tiles_var_sizes_[attribute_id] = tile_var_offset + bytes_to_fill_var; tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); } // Fill up current variable tile @@ -882,8 +922,10 @@ int WriteState::write_dense_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; // Compress current tile and write it to disk - if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_var_offset = 0; @@ -892,7 +934,7 @@ int WriteState::write_dense_attr_var_cmp_gzip( // Partially fill the (new) current tile bytes_to_fill = buffer_size - buffer_offset; if(bytes_to_fill != 0) { - memcpy(tile, shifted_buffer_c + buffer_offset, bytes_to_fill); + memcpy(tile + tile_offset, shifted_buffer_c + buffer_offset, bytes_to_fill); buffer_offset += bytes_to_fill; assert(buffer_offset == buffer_size); tile_offset += bytes_to_fill; @@ -906,6 +948,8 @@ int WriteState::write_dense_attr_var_cmp_gzip( tiles_var_sizes_[attribute_id] = tile_var_offset + bytes_to_fill_var; tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); } // Fill up current variable tile @@ -918,6 +962,9 @@ int WriteState::write_dense_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; } + // Clean up + free(shifted_buffer); + // Success return TILEDB_WS_OK; } @@ -960,6 +1007,10 @@ int WriteState::write_sparse_attr( int attribute_id, const void* buffer, size_t buffer_size) { + // Trivial case + if(buffer_size == 0) + return TILEDB_WS_OK; + // For easy reference const ArraySchema* array_schema = fragment_->array()->array_schema(); int compression = array_schema->compression(attribute_id); @@ -1059,7 +1110,7 @@ int WriteState::write_sparse_attr_cmp_gzip( // Partially fill the (new) current tile bytes_to_fill = buffer_size - buffer_offset; if(bytes_to_fill != 0) { - memcpy(tile, buffer_c + buffer_offset, bytes_to_fill); + memcpy(tile + tile_offset, buffer_c + buffer_offset, bytes_to_fill); buffer_offset += bytes_to_fill; assert(buffer_offset == buffer_size); tile_offset += bytes_to_fill; @@ -1075,6 +1126,10 @@ int WriteState::write_sparse_attr_var( size_t buffer_size, const void* buffer_var, size_t buffer_var_size) { + // Trivial case + if(buffer_size == 0) + return TILEDB_WS_OK; + // For easy reference const ArraySchema* array_schema = fragment_->array()->array_schema(); int compression = array_schema->compression(attribute_id); @@ -1213,8 +1268,10 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tile_offset += bytes_to_fill; // Compress current tile and write it to disk - if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_offset = 0; @@ -1223,6 +1280,8 @@ int WriteState::write_sparse_attr_var_cmp_gzip( while(tile_var_offset + bytes_to_fill_var > tiles_var_sizes_[attribute_id]) expand_buffer(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); // Fill up current variable tile memcpy( @@ -1233,8 +1292,10 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; // Compress current tile and write it to disk - if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_var_offset = 0; @@ -1248,8 +1309,10 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tile_offset += tile_size; // Compress and write current tile - if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_offset = 0; @@ -1268,6 +1331,8 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tiles_var_sizes_[attribute_id] = tile_var_offset + bytes_to_fill_var; tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); } // Fill up current variable tile @@ -1279,8 +1344,10 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; // Compress current tile and write it to disk - if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) + if(compress_and_write_tile_var(attribute_id) != TILEDB_WS_OK) { + free(shifted_buffer); return TILEDB_WS_ERR; + } // Update local tile buffer offset tile_var_offset = 0; @@ -1289,7 +1356,7 @@ int WriteState::write_sparse_attr_var_cmp_gzip( // Partially fill the (new) current tile bytes_to_fill = buffer_size - buffer_offset; if(bytes_to_fill != 0) { - memcpy(tile, shifted_buffer_c + buffer_offset, bytes_to_fill); + memcpy(tile + tile_offset, shifted_buffer_c + buffer_offset, bytes_to_fill); buffer_offset += bytes_to_fill; assert(buffer_offset == buffer_size); tile_offset += bytes_to_fill; @@ -1303,6 +1370,8 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tiles_var_sizes_[attribute_id] = tile_var_offset + bytes_to_fill_var; tiles_var_[attribute_id] = realloc(tiles_var_[attribute_id], tiles_var_sizes_[attribute_id]); + // Re-allocation may assign tiles_var_ to a different region of memory + tile_var = static_cast(tiles_var_[attribute_id]); } // Fill up current variable tile @@ -1315,6 +1384,9 @@ int WriteState::write_sparse_attr_var_cmp_gzip( tile_var_offset += bytes_to_fill_var; } + // Clean up + free(shifted_buffer); + // Success return TILEDB_WS_OK; } diff --git a/core/src/metadata/metadata.cc b/core/src/metadata/metadata.cc index c11633a7..e3ed75d9 100644 --- a/core/src/metadata/metadata.cc +++ b/core/src/metadata/metadata.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -353,6 +353,9 @@ void Metadata::compute_array_coords( coords_c = ((unsigned char*) coords) + i*4*sizeof(int); MD5(keys_c, key_size, coords_c); } + + // Clean up + free(keys_offsets); } void Metadata::prepare_array_buffers( diff --git a/core/src/metadata/metadata_iterator.cc b/core/src/metadata/metadata_iterator.cc index 2ef64903..69cdb5e3 100644 --- a/core/src/metadata/metadata_iterator.cc +++ b/core/src/metadata/metadata_iterator.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/src/misc/hilbert_curve.cc b/core/src/misc/hilbert_curve.cc index ce7f7cb5..5969d5a9 100755 --- a/core/src/misc/hilbert_curve.cc +++ b/core/src/misc/hilbert_curve.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/core/src/misc/utils.cc b/core/src/misc/utils.cc index 20b058e1..c3083369 100644 --- a/core/src/misc/utils.cc +++ b/core/src/misc/utils.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -569,7 +569,11 @@ bool is_positive_integer(const char* s) { template bool is_unary_subarray(const T* subarray, int dim_num) { - return !memcmp(subarray, &subarray[dim_num], dim_num*sizeof(T)); + for(int i=0; id_name; if(is_group(filename)) { // Group + if(dir_i == dir_num) { + PRINT_ERROR("Cannot list TileDB directory; Directory buffer overflow"); + return TILEDB_SM_ERR; + } strcpy(dirs[dir_i], next_file->d_name); dir_types[dir_i] = TILEDB_GROUP; ++dir_i; } else if(is_metadata(filename)) { // Metadata + if(dir_i == dir_num) { + PRINT_ERROR("Cannot list TileDB directory; Directory buffer overflow"); + return TILEDB_SM_ERR; + } strcpy(dirs[dir_i], next_file->d_name); dir_types[dir_i] = TILEDB_METADATA; ++dir_i; } else if(is_array(filename)){ // Array + if(dir_i == dir_num) { + PRINT_ERROR("Cannot list TileDB directory; Directory buffer overflow"); + return TILEDB_SM_ERR; + } strcpy(dirs[dir_i], next_file->d_name); dir_types[dir_i] = TILEDB_ARRAY; ++dir_i; } else if(is_workspace(filename)){ // Workspace + if(dir_i == dir_num) { + PRINT_ERROR("Cannot list TileDB directory; Directory buffer overflow"); + return TILEDB_SM_ERR; + } strcpy(dirs[dir_i], next_file->d_name); dir_types[dir_i] = TILEDB_WORKSPACE; ++dir_i; @@ -1015,6 +1037,9 @@ int StorageManager::create_master_catalog_entry( if(metadata->finalize() != TILEDB_MT_OK) return TILEDB_SM_ERR; + // Clean up + delete metadata; + // Success return TILEDB_SM_OK; } @@ -1182,8 +1207,7 @@ int StorageManager::master_catalog_consolidate() const { int StorageManager::master_catalog_create() const { // Create a metadata schema MetadataSchemaC metadata_schema_c = {}; - metadata_schema_c.metadata_name_ = - (char*) (tiledb_home_ + "/" + TILEDB_SM_MASTER_CATALOG).c_str(); + metadata_schema_c.metadata_name_ = (char*) master_catalog_dir_.c_str(); // Initialize array schema ArraySchema* array_schema = new ArraySchema(); diff --git a/doxygen/mainpage.dox b/doxygen/mainpage.dox index ed2b89e2..71bebb82 100644 --- a/doxygen/mainpage.dox +++ b/doxygen/mainpage.dox @@ -1,11 +1,11 @@ /*! - * @mainpage notitle + * @mainpage TileDB * * @section LICENSE * * The MIT License * - * @copyright Copyright (c) 2016 MIT and Intel Corp. + * @copyright Copyright (c) 2016 MIT and Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,11 +24,21 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - * - * @section Introduction + * @section About * - * TileDB is a new array database system. + * TileDB is a new system for efficient management of scientific data, i.e., of + * massive quantities of data that are naturally represented by + * multi-dimensional arrays. TileDB is written in C++ for Linux Ubuntu and Mac + * OS X, and open-sourced under the MIT license. The current release includes + * only the TileDB storage manager module exposed as a C API library, which + * makes it easy for programmers to write applications for diverse, complex, + * parallel, scientific data analytics. * - * [... Documentation Under Construction ...] + * + * Visit the TileDB website (http://istc-bigdata.org/tiledb/) to learn more + * about TileDB, as well as to read the detailed documentation on the internal + * TileDB mechanics and the usage of the C API library. Also check the TileDB + * GitHub wiki (https://github.com/Intel-HLS/TileDB/wiki) for installation + * guidelines and information about the code organization. */ diff --git a/examples/src/tiledb_array_consolidate.cc b/examples/src/tiledb_array_consolidate.cc index 31a7d1d7..982317bb 100644 --- a/examples/src/tiledb_array_consolidate.cc +++ b/examples/src/tiledb_array_consolidate.cc @@ -1,33 +1,80 @@ -/* - * Demonstrates how to write to dense array "workspace/A", in dense mode. +/** + * @file tiledb_array_consolidate.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to consolidate arrays. */ #include "c_api.h" -#include int main() { - /* Intialize context with the default configuration parameters. */ + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - /* Initialize the array in WRITE mode. */ + // ----- Dense array + + // Initialize array TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_WRITE, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Consolidate array. */ + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Consolidate array + tiledb_array_consolidate(tiledb_array); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // ----- Sparse array + + // Initialize array + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Consolidate array tiledb_array_consolidate(tiledb_array); - /* Finalize the array. */ + // Finalize array tiledb_array_finalize(tiledb_array); - /* Finalize context. */ + // Finalize context tiledb_ctx_finalize(tiledb_ctx); return 0; diff --git a/examples/src/tiledb_array_create_dense.cc b/examples/src/tiledb_array_create_dense.cc new file mode 100644 index 00000000..6d2b593c --- /dev/null +++ b/examples/src/tiledb_array_create_dense.cc @@ -0,0 +1,107 @@ +/** + * @file tiledb_array_create_dense.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to create a dense array. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Prepare parameters for array schema + const char* array_name = "my_workspace/dense_arrays/my_array_A"; + const char* attributes[] = { "a1", "a2", "a3" }; // Three attributes + const char* dimensions[] = { "d1", "d2" }; // Two dimensions + int64_t domain[] = + { + 1, 4, // d1 + 1, 4 // d2 + }; + const int cell_val_num[] = + { + 1, // a1 + TILEDB_VAR_NUM, // a2 + 2 // a3 + }; + const int compression[] = + { + TILEDB_GZIP, // a1 + TILEDB_GZIP, // a2 + TILEDB_NO_COMPRESSION, // a3 + TILEDB_NO_COMPRESSION // coordinates + }; + int64_t tile_extents[] = + { + 2, // d1 + 2 // d2 + }; + const int types[] = + { + TILEDB_INT32, // a1 + TILEDB_CHAR, // a2 + TILEDB_FLOAT32, // a3 + TILEDB_INT64 // coordinates + }; + + // Set array schema + TileDB_ArraySchema array_schema; + tiledb_array_set_schema( + &array_schema, // Array schema struct + array_name, // Array name + attributes, // Attributes + 3, // Number of attributes + 2, // Capacity + TILEDB_ROW_MAJOR, // Cell order + cell_val_num, // Number of cell values per attribute + compression, // Compression + 1, // Dense array + dimensions, // Dimensions + 2, // Number of dimensions + domain, // Domain + 4*sizeof(int64_t), // Domain length in bytes + tile_extents, // Tile extents + 2*sizeof(int64_t), // Tile extents length in bytes + TILEDB_ROW_MAJOR, // Tile order + types // Types + ); + + // Create array + tiledb_array_create(tiledb_ctx, &array_schema); + + // Free array schema + tiledb_array_free_schema(&array_schema); + + /* Finalize context. */ + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_create_dense_A.cc b/examples/src/tiledb_array_create_dense_A.cc deleted file mode 100644 index 5181ae88..00000000 --- a/examples/src/tiledb_array_create_dense_A.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * File: tiledb_array_create_dense_A.cc - * - * Demonstrates how to create a dense array, called "dense_A". - */ - -#include "c_api.h" -#include -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - // Set array schema - TileDB_ArraySchema array_schema; - const char* attributes[] = { "a1", "a2" }; - const char* dimensions[] = { "d1", "d2" }; - int64_t domain[] = { 1, 4, 1, 4 }; - int64_t tile_extents[] = { 2, 2 }; - const int types[] = { TILEDB_INT32, TILEDB_FLOAT32, TILEDB_INT64 }; - const int compression[] = - { TILEDB_GZIP, TILEDB_NO_COMPRESSION, TILEDB_NO_COMPRESSION }; - tiledb_array_set_schema( - // The array schema struct - &array_schema, - // Array name - "workspace/dense_A", - // Attributes - attributes, - // Number of attributes - 2, - // Dimensions - dimensions, - // Number of dimensions - 2, - // Dense array - 1, - // Domain - domain, - // Domain length in bytes - 4*sizeof(int64_t), - // Tile extents (no regular tiles defined) - tile_extents, - // Tile extents in bytes - 2*sizeof(int64_t), - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - NULL, - // Cell order - TILEDB_COL_MAJOR, - // Tile order (0 means ignore in sparse arrays and default in dense) - 0, - // Capacity - 4, - // Compression - compression - ); - - /* Create the array. */ - tiledb_array_create(tiledb_ctx, &array_schema); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_create_dense_var_A.cc b/examples/src/tiledb_array_create_dense_var_A.cc deleted file mode 100644 index 19b0b9d6..00000000 --- a/examples/src/tiledb_array_create_dense_var_A.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * File: tiledb_array_create_dense_var_A.cc - * - * Demonstrates how to create a dense array, called "dense_var_A". - */ - -#include "c_api.h" -#include -#include - -int main() { - /* Initialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* - * Prepare the array schema struct, initializing all numeric members to 0 - * and pointers to NULL. - */ - TileDB_ArraySchema array_schema; - - // Set array schema - const char* attributes[] = { "a1", "a2" }; - const char* dimensions[] = { "d1", "d2" }; - int64_t domain[] = { 1, 4, 1, 4 }; - int64_t tile_extents[] = { 2, 2 }; - const int types[] = { TILEDB_CHAR, TILEDB_FLOAT32, TILEDB_INT64 }; - const int cell_val_num[] = { TILEDB_VAR_NUM, 1 }; - tiledb_array_set_schema( - // The array schema object - &array_schema, - // Array name - "workspace/dense_var_A", - // Attributes - attributes, - // Number of attributes - 2, - // Dimensions - dimensions, - // Number of dimensions - 2, - // Dense array - 1, - // Domain - domain, - // Domain length in bytes - 4*sizeof(int64_t), - // Tile extents (no regular tiles defined) - tile_extents, - // Tile extents in bytes - 2*sizeof(int64_t), - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - cell_val_num, - // Cell order - TILEDB_ROW_MAJOR, - // Tile order (0 means ignore in sparse arrays and default in dense) - 0, - // Capacity - 4, - // Compression - NULL - ); - - /* Create the array. */ - tiledb_array_create(tiledb_ctx, &array_schema); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_create_sparse.cc b/examples/src/tiledb_array_create_sparse.cc new file mode 100644 index 00000000..c2505e80 --- /dev/null +++ b/examples/src/tiledb_array_create_sparse.cc @@ -0,0 +1,102 @@ +/** + * @file tiledb_array_create_sparse.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to create a sparse array. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Prepare parameters for array schema + const char* array_name = "my_workspace/sparse_arrays/my_array_B"; + const char* attributes[] = { "a1", "a2", "a3" }; // Three attributes + const char* dimensions[] = { "d1", "d2" }; // Two dimensions + int64_t domain[] = + { + 1, 4, // d1 + 1, 4 // d2 + }; + const int cell_val_num[] = + { + 1, // a1 + TILEDB_VAR_NUM, // a2 + 2 // a3 + }; + const int compression[] = + { + TILEDB_GZIP, // a1 + TILEDB_GZIP, // a2 + TILEDB_NO_COMPRESSION, // a3 + TILEDB_NO_COMPRESSION // coordinates + }; + const int types[] = + { + TILEDB_INT32, // a1 + TILEDB_CHAR, // a2 + TILEDB_FLOAT32, // a3 + TILEDB_INT64 // coordinates + }; + + // Set array schema + TileDB_ArraySchema array_schema; + tiledb_array_set_schema( + &array_schema, // Array schema struct + array_name, // Array name + attributes, // Attributes + 3, // Number of attributes + 2, // Capacity + TILEDB_HILBERT, // Cell order + cell_val_num, // Number of cell values per attribute + compression, // Compression + 0, // Sparse array + dimensions, // Dimensions + 2, // Number of dimensions + domain, // Domain + 4*sizeof(int64_t), // Domain length in bytes + NULL, // Tile extents + 0, // Tile extents length in bytes + 0, // Tile order (will be ingored) + types // Types + ); + + // Create array + tiledb_array_create(tiledb_ctx, &array_schema); + + // Free array schema + tiledb_array_free_schema(&array_schema); + + /* Finalize context. */ + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_create_sparse_A.cc b/examples/src/tiledb_array_create_sparse_A.cc deleted file mode 100644 index 0b1b9766..00000000 --- a/examples/src/tiledb_array_create_sparse_A.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * File: tiledb_array_create_sparse_A.cc - * - * Demonstrates how to create a sparse array, called "sparse_A". - */ - -#include "c_api.h" -#include -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* - * Prepare the array schema struct, initalizing all numeric members to 0 - * and pointers to NULL. - */ - TileDB_ArraySchema array_schema; - - // Set array schema - const char* attributes[] = { "a1", "a2" }; - const char* dimensions[] = { "d1", "d2" }; - int64_t domain[] = { 1, 4, 1, 4 }; - const int types[] = { TILEDB_INT32, TILEDB_FLOAT32, TILEDB_INT64 }; - const int compression[] = - { TILEDB_GZIP, TILEDB_NO_COMPRESSION, TILEDB_NO_COMPRESSION }; - tiledb_array_set_schema( - // The array schema struct - &array_schema, - // Array name - "workspace/sparse_A", - // Attributes - attributes, - // Number of attributes - 2, - // Dimensions - dimensions, - // Number of dimensions - 2, - // Sparse array - 0, - // Domain - domain, - // Domain length in bytes - 4*sizeof(int64_t), - // Tile extents (no regular tiles defined) - NULL, - // Tile extents in bytes - 0, - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - NULL, - // Cell order - TILEDB_COL_MAJOR, - // Tile order (0 means ignore in sparse arrays and default in dense) - 0, - // Capacity - 4, - // Compression - compression - ); - - /* Create the array. */ - tiledb_array_create(tiledb_ctx, &array_schema); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_create_sparse_var_A.cc b/examples/src/tiledb_array_create_sparse_var_A.cc deleted file mode 100644 index 36a65ea6..00000000 --- a/examples/src/tiledb_array_create_sparse_var_A.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * File: tiledb_array_create_sparse_A.cc - * - * Demonstrates how to create a sparse array, called "sparse_A". - */ - -#include "c_api.h" -#include -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* - * Prepare the array schema struct, initalizing all numeric members to 0 - * and pointers to NULL. - */ - TileDB_ArraySchema array_schema; - - // Set array schema - const char* attributes[] = { "a1", "a2" }; - const char* dimensions[] = { "d1", "d2" }; - int64_t domain[] = { 1, 4, 1, 4 }; - const int types[] = { TILEDB_CHAR, TILEDB_FLOAT32, TILEDB_INT64 }; - const int cell_val_num[] = { TILEDB_VAR_NUM, 1 }; - const int compression[] = - { TILEDB_GZIP, TILEDB_NO_COMPRESSION, TILEDB_NO_COMPRESSION }; - tiledb_array_set_schema( - // The array schema struct - &array_schema, - // Array name - "workspace/sparse_var_A", - // Attributes - attributes, - // Number of attributes - 2, - // Dimensions - dimensions, - // Number of dimensions - 2, - // Sparse array - 0, - // Domain - domain, - // Domain length in bytes - 4*sizeof(int64_t), - // Tile extents (no regular tiles defined) - NULL, - // Tile extents in bytes - 0, - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - cell_val_num, - // Cell order - TILEDB_ROW_MAJOR, - // Tile order (0 means ignore in sparse arrays and default in dense) - 0, - // Capacity - 4, - // Compression - compression - ); - - /* Create the array. */ - tiledb_array_create(tiledb_ctx, &array_schema); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_get_schema_dense_B.cc b/examples/src/tiledb_array_get_schema_dense_B.cc deleted file mode 100644 index b3994a48..00000000 --- a/examples/src/tiledb_array_get_schema_dense_B.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * - * Demonstrates how to create a dense array, called "dense_A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 1, 8, 1, 8 }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_READ, - range, - NULL, - 1); - - // Get array schema - TileDB_ArraySchema array_schema; - tiledb_array_get_schema(tiledb_array, &array_schema); - - // Print schema - std::cout << "Array name:\n"; - std::cout << array_schema.array_name_ << "\n"; - std::cout << "Attribute num:\n"; - std::cout << array_schema.attribute_num_ << "\n"; - std::cout << "Attributes:\n"; - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Prepare cell buffers + int buffer_a1[3]; + void* buffers[] = { buffer_a1 }; + size_t buffer_sizes[] = { sizeof(buffer_a1) }; + + // Subarray and attributes + int64_t subarray[] = { 3, 4, 2, 4 }; + const char* attributes[] = { "a1" }; + + // Initialize array + TileDB_ArrayIterator* tiledb_array_it; + tiledb_array_iterator_init( + tiledb_ctx, // Context + &tiledb_array_it, // Array iterator + "my_workspace/dense_arrays/my_array_A", // Array name + subarray, // Constrain in subarray + attributes, // Subset on attributes + 1, // Number of attributes + buffers, // Buffers used internally + buffer_sizes); // Buffer sizes + + // Iterate over all values in subarray + printf(" a1\n----\n"); + const int* a1_v; + size_t a1_size; + while(!tiledb_array_iterator_end(tiledb_array_it)) { + // Get value + tiledb_array_iterator_get_value( + tiledb_array_it, // Array iterator + 0, // Attribute id + (const void**) &a1_v,// Value + &a1_size); // Value size (useful in variable-sized attributes) + printf("%3d\n", *a1_v); + + // Advance iterator + tiledb_array_iterator_next(tiledb_array_it); + } + + // Finalize array + tiledb_array_iterator_finalize(tiledb_array_it); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_iterator_read_dense_B.cc b/examples/src/tiledb_array_iterator_read_dense_B.cc deleted file mode 100644 index a9fdd511..00000000 --- a/examples/src/tiledb_array_iterator_read_dense_B.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 2, 3, 1, 2 }; - - /* Subset over attribute "a1". */ - //const char* attributes[] = { "a1" }; - const char* attributes[] = { "a2" }; - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[8]; - size_t buffer_a2[8]; - char buffer_a2_var[50]; - float buffer_a3[128]; - //void* buffers[] = { buffer_a1 }; - //size_t buffer_sizes[] = { sizeof(buffer_a1) }; - void* buffers[] = { buffer_a2, buffer_a2_var }; - size_t buffer_sizes[] = { sizeof(buffer_a2), sizeof(buffer_a2_var) }; - - /* Initialize the array in READ mode. */ - TileDB_ArrayIterator* tiledb_array_iterator; - tiledb_array_iterator_init( - tiledb_ctx, - &tiledb_array_iterator, - "workspace/dense_B", - NULL, // range, - attributes, - 1, - buffers, - buffer_sizes); - - /* Read from array. */ - const char* b; - size_t b_size; - - while(!tiledb_array_iterator_end(tiledb_array_iterator)) { - tiledb_array_iterator_get_value(tiledb_array_iterator, 0, (const void**) &b, &b_size); - std::cout << b << " " << b_size << "\n"; - tiledb_array_iterator_next(tiledb_array_iterator); - } - - /* Finalize the array iterator. */ - tiledb_array_iterator_finalize(tiledb_array_iterator); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_iterator_sparse.cc b/examples/src/tiledb_array_iterator_sparse.cc new file mode 100644 index 00000000..f5844578 --- /dev/null +++ b/examples/src/tiledb_array_iterator_sparse.cc @@ -0,0 +1,89 @@ +/** + * @file tiledb_array_iterator_sparse.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to use an iterator for sparse arrays. + */ + +#include "c_api.h" +#include + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Prepare cell buffers + int buffer_a1[3]; + void* buffers[] = { buffer_a1 }; + size_t buffer_sizes[] = { sizeof(buffer_a1) }; + + // Subarray and attributes + int64_t subarray[] = { 3, 4, 2, 4 }; + const char* attributes[] = { "a1" }; + + // Initialize array + TileDB_ArrayIterator* tiledb_array_it; + tiledb_array_iterator_init( + tiledb_ctx, // Context + &tiledb_array_it, // Array iterator + "my_workspace/sparse_arrays/my_array_B", // Array name + subarray, // Constrain in subarray + attributes, // Subset on attributes + 1, // Number of attributes + buffers, // Buffers used internally + buffer_sizes); // Buffer sizes + + // Iterate over all values in subarray + printf(" a1\n----\n"); + const int* a1_v; + size_t a1_size; + while(!tiledb_array_iterator_end(tiledb_array_it)) { + // Get value + tiledb_array_iterator_get_value( + tiledb_array_it, // Array iterator + 0, // Attribute id + (const void**) &a1_v,// Value + &a1_size); // Value size (useful in variable-sized attributes) + + // Print value (if not a deletion) + if(*a1_v != TILEDB_EMPTY_INT32) + printf("%3d\n", *a1_v); + + // Advance iterator + tiledb_array_iterator_next(tiledb_array_it); + } + + // Finalize array + tiledb_array_iterator_finalize(tiledb_array_it); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_load_schema_sparse_B.cc b/examples/src/tiledb_array_load_schema_sparse_B.cc deleted file mode 100644 index 12b096f1..00000000 --- a/examples/src/tiledb_array_load_schema_sparse_B.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - * - * Demonstrates how to create a dense array, called "dense_A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - // Get array schema - TileDB_ArraySchema array_schema; - tiledb_array_load_schema(tiledb_ctx, "workspace/sparse_B", &array_schema); - - // Print schema - std::cout << "Array name:\n"; - std::cout << array_schema.array_name_ << "\n"; - std::cout << "Attribute num:\n"; - std::cout << array_schema.attribute_num_ << "\n"; - std::cout << "Attributes:\n"; - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i(array_schema.domain_); - for(int i=0; i(array_schema.tile_extents_); - if(tile_extents == NULL) { - std::cout << "NULL\n"; - } else { - for(int i=0; i + +// Prints some schema info (you can enhance this to print the entire schema) +void print_some_array_schema_info(const TileDB_ArraySchema* array_schema); + +int main() { + /* Intialize context with the default configuration parameters. */ + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // ----- Dense array ----- // + + // Load array schema when the array is not initialized + TileDB_ArraySchema array_schema; + tiledb_array_load_schema( + tiledb_ctx, // Context + "my_workspace/dense_arrays/my_array_A", // Array name + &array_schema); // Array schema struct + + // Print some array schema info + print_some_array_schema_info(&array_schema); + + // Free array schema + tiledb_array_free_schema(&array_schema); + + // ----- Sparse array ----- // + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_READ, // Mode + NULL, // Subarray (whole domain) + NULL, // Attributes (all attributes) + 0); // Number of attributes + + // Get array schema when the array is initialized + tiledb_array_get_schema(tiledb_array, &array_schema); + + // Print some schema info + print_some_array_schema_info(&array_schema); + + // Free array schema + tiledb_array_free_schema(&array_schema); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} + +void print_some_array_schema_info(const TileDB_ArraySchema* array_schema) { + printf("Array name: %s\n", array_schema->array_name_); + printf("Attributes: "); + for(int i=0; iattribute_num_; ++i) + printf("%s ", array_schema->attributes_[i]); + printf("\n"); + if(array_schema->dense_) + printf("The array is dense\n"); + else + printf("The array is sparse\n"); +} diff --git a/examples/src/tiledb_array_read_dense_1.cc b/examples/src/tiledb_array_read_dense_1.cc new file mode 100644 index 00000000..78d8d1c7 --- /dev/null +++ b/examples/src/tiledb_array_read_dense_1.cc @@ -0,0 +1,88 @@ +/** + * @file tiledb_array_read_dense_1.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to read a complete dense array. + */ + +#include "c_api.h" +#include + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_READ, // Mode + NULL, // Whole domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[16]; + size_t buffer_a2[16]; + char buffer_var_a2[40]; + float buffer_a3[32]; + void* buffers[] = { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3 }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2), + sizeof(buffer_a3) + }; + + // Read from array + tiledb_array_read(tiledb_array, buffers, buffer_sizes); + + // Print cell values + int64_t result_num = buffer_sizes[0] / sizeof(int); + printf(" a1\t a2\t (a3.first, a3.second)\n"); + printf("-----------------------------------------\n"); + for(int i=0; i + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Subarray and attributes + int64_t subarray[] = { 3, 4, 2, 4 }; + const char* attributes[] = { "a1" }; + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_READ, // Mode + subarray, // Constrain in subarray + attributes, // Subset on attributes + 1); // Number of attributes + + // Prepare cell buffers + int buffer_a1[3]; + void* buffers[] = { buffer_a1 }; + size_t buffer_sizes[] = { sizeof(buffer_a1) }; + + + // Loop until no overflow + printf(" a1\n----\n"); + do { + printf("Reading cells...\n"); + + // Read from array + tiledb_array_read(tiledb_array, buffers, buffer_sizes); + + // Print cell values + int64_t result_num = buffer_sizes[0] / sizeof(int); + for(int i=0; i + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Subarray and attributes + int64_t subarray[] = { 3, 3, 2, 2 }; + int64_t subarray_2[] = { 4, 4, 3, 3 }; + const char* attributes[] = { "a1" }; + const char* attributes_2[] = { "a2" }; + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_READ, // Mode + subarray, // Constrain in subarray + attributes, // Subset on attributes + 1); // Number of attributes + + // Prepare cell buffers + int buffer_a1[1]; + size_t buffer_a2[1]; + char buffer_var_a2[10]; + void* buffers[] = { buffer_a1 }; + void* buffers_2[] = { buffer_a2, buffer_var_a2 }; + size_t buffer_sizes[] = { sizeof(buffer_a1) }; + size_t buffer_sizes_2[] = { sizeof(buffer_a2), sizeof(buffer_var_a2) }; + + // Read from array - #1 + tiledb_array_read(tiledb_array, buffers, buffer_sizes); + printf("a1 for (3,2): %3d\n", buffer_a1[0]); + + // Reset subarray and attributes + tiledb_array_reset_subarray(tiledb_array, subarray_2); + tiledb_array_reset_attributes(tiledb_array, attributes_2, 1); + + // Read from array - #2 + tiledb_array_read(tiledb_array, buffers_2, buffer_sizes_2); + printf("a2 for (4,3): %3.*s\n", buffer_sizes_2[1], buffer_var_a2); + + // Finalize the array + tiledb_array_finalize(tiledb_array); + + /* Finalize context. */ + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_read_dense_A.cc b/examples/src/tiledb_array_read_dense_A.cc deleted file mode 100644 index 2fb1d6b0..00000000 --- a/examples/src/tiledb_array_read_dense_A.cc +++ /dev/null @@ -1,52 +0,0 @@ -/* - * File: tiledb_array_read_dense_A.cc - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 2, 2, 1, 4 }; - - /* Subset over attribute "a1". */ - const char* attributes[] = { "a1" }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_A", - TILEDB_ARRAY_READ, - range, - attributes, - 1); - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[10]; - void* buffers[] = { buffer_a1 }; - size_t buffer_sizes[1] = { sizeof(buffer_a1) }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - int64_t result_num = buffer_sizes[0] / sizeof(int); - for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 2, 3, 2, 3 }; - - /* Subset over attribute "a1". */ - const char* attributes[] = { "a1" }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_var_A", - TILEDB_ARRAY_READ, - range, - attributes, - 1); - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[16]; - char buffer_var_a1[66]; - void* buffers[] = { buffer_a1, buffer_var_a1 }; - size_t buffer_sizes[] = { sizeof(buffer_a1), 66 }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - int64_t result_num = buffer_sizes[0] / sizeof(size_t); - for(int i=0; i + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_READ, // Mode + NULL, // Whole domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[10]; + size_t buffer_a2[10]; + char buffer_var_a2[30]; + float buffer_a3[20]; + int64_t buffer_coords[20]; + void* buffers[] = + { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3, buffer_coords }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2), + sizeof(buffer_a3), + sizeof(buffer_coords) + }; + + // Read from array + tiledb_array_read(tiledb_array, buffers, buffer_sizes); + + // Print cell values + int64_t result_num = buffer_sizes[0] / sizeof(int); + printf("coords\t a1\t a2\t (a3.first, a3.second)\n"); + printf("--------------------------------------------------\n"); + for(int i=0; i + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Subarray and attributes + int64_t subarray[] = { 3, 4, 2, 4 }; + const char* attributes[] = { "a1" }; + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_READ, // Mode + subarray, // Constrain in subarray + attributes, // Subset on attributes + 1); // Number of attributes + + // Prepare cell buffers + int buffer_a1[2]; + void* buffers[] = { buffer_a1 }; + size_t buffer_sizes[] = { sizeof(buffer_a1) }; + + + // Loop until no overflow + printf(" a1\n----\n"); + do { + printf("Reading cells...\n"); + + // Read from array + tiledb_array_read(tiledb_array, buffers, buffer_sizes); + + // Print cell values + int64_t result_num = buffer_sizes[0] / sizeof(int); + for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 2, 3, 1, 4 }; - - /* Subset over attribute "a1" and the coordinates. */ - const char* attributes[] = { "a1", TILEDB_COORDS }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_A", - TILEDB_ARRAY_READ, - range, - attributes, - 2); - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[9]; - int64_t buffer_coords[18]; - void* buffers[] = { buffer_a1, buffer_coords }; - size_t buffer_sizes[2] = { 6*sizeof(int), 12*sizeof(int64_t) }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - int result_num = buffer_sizes[0] / sizeof(int); - for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 3, 3, 3, 3 }; - - /* Subset over attribute "a1" and the coordinates. */ - const char* attributes[] = { TILEDB_COORDS, "a1" }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_var_A", - TILEDB_ARRAY_READ, - range, - attributes, - 2); - - /* Prepare cell buffers for attribute "a1". */ - size_t buffer_a1[6]; - int64_t buffer_coords[12]; - char buffer_var_a1[26]; - void* buffers[] = { buffer_coords, buffer_a1, buffer_var_a1 }; - size_t buffer_sizes[] = { - sizeof(buffer_coords), - sizeof(buffer_a1), - sizeof(buffer_var_a1) }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - int result_num = buffer_sizes[0] / sizeof(int64_t) / 2; - for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Subset over attribute "a1" and the coordinates. */ - const char* attributes[] = { "a1", "a2", TILEDB_COORDS }; - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_A", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - attributes, // No projection - all attributes - 3); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[6]; - float buffer_a2[6]; - int64_t buffer_coords[12]; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_coords}; - size_t buffer_sizes[3] = { - 6*sizeof(int) , - 6*sizeof(float), - 12*sizeof(int64_t) }; - - /* Populate attribute buffers with some arbitrary values. */ - for(int i=0; i<6; ++i) { - buffer_a1[i] = i; - buffer_a2[i] = 100.0 + i; - } - - /* Populate coordinates buffer with some arbitrary values. */ - buffer_coords[0] = 1; buffer_coords[1] = 1; - buffer_coords[2] = 2; buffer_coords[3] = 1; - buffer_coords[4] = 2; buffer_coords[5] = 2; - buffer_coords[6] = 4; buffer_coords[7] = 2; - buffer_coords[8] = 3; buffer_coords[9] = 3; - buffer_coords[10] = 1; buffer_coords[11] = 4; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_update_read_dense_B.cc b/examples/src/tiledb_array_update_read_dense_B.cc deleted file mode 100644 index e6a2ba10..00000000 --- a/examples/src/tiledb_array_update_read_dense_B.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * File: tiledb_array_read_dense_A.cc - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 1, 8, 1, 8 }; - - /* Subset over attribute "a1". */ - const char* attributes[] = { "a1" }; - //const char* attributes[] = { "a2" }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_READ, - range, - attributes, - 1); - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[64]; - size_t buffer_a2[64]; - char buffer_a2_var[500]; - float buffer_a3[128]; - void* buffers[] = { buffer_a1 }; - size_t buffer_sizes[] = { sizeof(buffer_a1) }; - //void* buffers[] = { buffer_a2, buffer_a2_var }; - //size_t buffer_sizes[] = { sizeof(buffer_a2), sizeof(buffer_a2_var) }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - //int64_t result_num = buffer_sizes[0] / sizeof(int); - int64_t result_num = buffer_sizes[0] / sizeof(size_t); - for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize a range. */ - const int64_t range[] = { 1, 8, 1, 8 }; - - /* Subset over attribute "a1". */ - //const char* attributes[] = { "a1", TILEDB_COORDS_NAME }; - const char* attributes[] = { "a2", TILEDB_COORDS }; - //const char* attributes[] = { "a2" }; - - /* Initialize the array in READ mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_B", - TILEDB_ARRAY_READ, - range, - attributes, - 2); - - /* Prepare cell buffers for attribute "a1". */ - int64_t buffer_coords[128]; - int buffer_a1[64]; - size_t buffer_a2[64]; - char buffer_a2_var[500]; - float buffer_a3[128]; - //void* buffers[] = { buffer_a1, buffer_coords }; - //size_t buffer_sizes[] = { sizeof(buffer_a1), sizeof(buffer_coords) }; - void* buffers[] = { buffer_a2, buffer_a2_var, buffer_coords }; - size_t buffer_sizes[] = { sizeof(buffer_a2), sizeof(buffer_a2_var), sizeof(buffer_coords) }; - - /* Read from array. */ - tiledb_array_read(tiledb_array, buffers, buffer_sizes); - - /* Print the read values. */ - //int64_t result_num = buffer_sizes[0] / sizeof(int); - int64_t result_num = buffer_sizes[0] / sizeof(int); - for(int i=0; i - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_WRITE, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[64]; - size_t buffer_a2[] = - { - 0, 2, 5, 9, 14, 20, 27, 35, - 44, 46, 49, 53, 58, 64, 71, 79, - 88, 90, 93, 97, 102, 108, 115, 123, - 132, 134, 137, 141, 146, 152, 159, 167, - 176, 178, 181, 185, 190, 196, 203, 211, - 220, 222, 225, 229, 234, 240, 247, 255, - 264, 266, 269, 273, 278, 284, 291, 299, - 308, 310, 313, 317, 322, 328, 335, 343 - }; - char buffer_a2_var[] = - { - "a\0bb\0ccc\0dddd\0eeeee\0ffffff\0ggggggg\0hhhhhhhh\0" - "i\0jj\0kkk\0llll\0mmmmm\0nnnnnn\0ooooooo\0pppppppp\0" - "q\0rr\0sss\0tttt\0uuuuu\0vvvvvv\0wwwwwww\0xxxxxxxx\0" - "y\0zz\0!!!\0@@@@\0#####\0$$$$$$\0^^^^^^^\0********\0" - "a\0bb\0ccc\0dddd\0eeeee\0ffffff\0ggggggg\0hhhhhhhh\0" - "i\0jj\0kkk\0llll\0mmmmm\0nnnnnn\0ooooooo\0pppppppp\0" - "q\0rr\0sss\0tttt\0uuuuu\0vvvvvv\0wwwwwww\0xxxxxxxx\0" - "y\0zz\0!!!\0@@@@\0#####\0$$$$$$\0^^^^^^^\0********" - }; - float buffer_a3[128]; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_a2_var, buffer_a3 }; - size_t buffer_sizes[] = - { - sizeof(buffer_a1) , - sizeof(buffer_a2), - sizeof(buffer_a2_var), - sizeof(buffer_a3) - }; - - /* Populate buffers with some arbitrary values. */ - for(int i=0; i<64; ++i) { - buffer_a1[i] = i; - buffer_a3[2*i] = i + 0.1; - buffer_a3[2*i+1] = i + 0.2; - } - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_update_write_dense_B_2.cc b/examples/src/tiledb_array_update_write_dense_B_2.cc deleted file mode 100644 index 5c3d4c47..00000000 --- a/examples/src/tiledb_array_update_write_dense_B_2.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Demonstrates how to write to dense array "workspace/A", in dense mode. - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - const int64_t range[] = { 3, 4, 6, 8 }; - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_WRITE, - range, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[] = - { - TILEDB_EMPTY_INT32, 125, TILEDB_EMPTY_INT32, 127, - 128, 129, 130, 131 - }; - size_t buffer_a2[] = - { - 0, 1, 2, 3, 4, 5, 6, 7 - }; - char buffer_a2_var[] = - { - TILEDB_EMPTY_CHAR, '+', TILEDB_EMPTY_CHAR, '+', - '+', '+', '+', '+' - }; - float buffer_a3[] = - { - TILEDB_EMPTY_FLOAT32, TILEDB_EMPTY_FLOAT32, 125.1, 125.2, - TILEDB_EMPTY_FLOAT32, TILEDB_EMPTY_FLOAT32, 127.1, 127.2, - 128.1, 128.2, 129.1, 129.2, 130.1, 130.2, 131.1, 131.2 - }; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_a2_var, buffer_a3 }; - size_t buffer_sizes[] = - { - sizeof(buffer_a1) , - sizeof(buffer_a2), - sizeof(buffer_a2_var), - sizeof(buffer_a3) - }; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_update_write_dense_B_3.cc b/examples/src/tiledb_array_update_write_dense_B_3.cc deleted file mode 100644 index bf01a5e5..00000000 --- a/examples/src/tiledb_array_update_write_dense_B_3.cc +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Demonstrates how to write to sparse array "workspace/sparse_A", in - * in unsorted mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - const char* attributes[] = {TILEDB_COORDS, "a1", "a2", "a3"}; - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_B", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - attributes, // No projection - all attributes - 4); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int64_t buffer_coords[] - { - 4, 4, - 4, 6, - 5, 6, -// 5, 8, - 5, 7, - 7, 1, - 7, 2, - 8, 3 - }; - int buffer_a1[] = - { - 223, 227, 241, 244, 248, 249, 254 - }; - size_t buffer_a2[] = - { - 0, 1, 2, 3, 4, 5, 6 - }; - char buffer_var_a2[] = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G' - }; - float buffer_a3[] = - { - 223.1, 223.2, - 227.1, 227.2, - 241.1, 241.2, - 244.1, 244.2, - 248.1, 248.2, - 249.1, 249.2, - 254.1, 254.2 - }; - const void* buffers[] = - { - buffer_coords, buffer_a1, buffer_a2, buffer_var_a2, buffer_a3 - }; - size_t buffer_sizes[] = { - sizeof(buffer_coords), - sizeof(buffer_a1), - sizeof(buffer_a2), - sizeof(buffer_var_a2), - sizeof(buffer_a3) }; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_update_write_sparse_B_1.cc b/examples/src/tiledb_array_update_write_sparse_B_1.cc deleted file mode 100644 index eda323e7..00000000 --- a/examples/src/tiledb_array_update_write_sparse_B_1.cc +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Demonstrates how to write to sparse array "workspace/sparse_A", in - * in unsorted mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - const char* attributes[] = {TILEDB_COORDS, "a1", "a2", "a3"}; - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_B", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - attributes, // No projection - all attributes - 4); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int64_t buffer_coords[] - { - 4, 4, - 4, 6, - 5, 6, -// 5, 8, - 5, 7, - 7, 1, - 7, 2, - 8, 3 - }; - int buffer_a1[] = - { - 223, 227, 241, 244, 248, 249, 254 - }; - size_t buffer_a2[] = - { - 0, 1, 2, 3, 4, 5, 6 - }; - char buffer_var_a2[] = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G' - }; - float buffer_a3[] = - { - 223.1, 223.2, - 227.1, 227.2, - 241.1, 241.2, - 244.1, 244.2, - 248.1, 248.2, - 249.1, 249.2, - 254.1, 254.2 - }; - const void* buffers[] = - { - buffer_coords, buffer_a1, buffer_a2, buffer_var_a2, buffer_coords - }; - size_t buffer_sizes[] = { - sizeof(buffer_coords), - sizeof(buffer_a1), - sizeof(buffer_a2), - sizeof(buffer_var_a2), - sizeof(buffer_a3) }; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_update_write_sparse_B_2.cc b/examples/src/tiledb_array_update_write_sparse_B_2.cc deleted file mode 100644 index 3944ff14..00000000 --- a/examples/src/tiledb_array_update_write_sparse_B_2.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Demonstrates how to write to sparse array "workspace/sparse_A", in - * in unsorted mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - const char* attributes[] = {TILEDB_COORDS, "a1", "a2", "a3"}; - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_B", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - attributes, // No projection - all attributes - 4); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int64_t buffer_coords[] - { - 3, 3, - // 4, 4, - 4, 6, - 5, 6, - 5, 8, -// 5, 7, - 7, 1, - 7, 2, - 8, 3 - }; - int buffer_a1[] = - { - 323, 327, 341, 344, 348, 349, 354 - }; - size_t buffer_a2[] = - { - 0, 1, 2, 3, 4, 5, 6 - }; - char buffer_var_a2[] = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G' - }; - float buffer_a3[] = - { - 223.1, 223.2, - 227.1, 227.2, - 241.1, 241.2, - 244.1, 244.2, - 248.1, 248.2, - 249.1, 249.2, - 254.1, 254.2 - }; - const void* buffers[] = - { - buffer_coords, buffer_a1, buffer_a2, buffer_var_a2, buffer_coords - }; - size_t buffer_sizes[] = { - sizeof(buffer_coords), - sizeof(buffer_a1), - sizeof(buffer_a2), - sizeof(buffer_var_a2), - sizeof(buffer_a3) }; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_dense_1.cc b/examples/src/tiledb_array_write_dense_1.cc new file mode 100644 index 00000000..357a1d4b --- /dev/null +++ b/examples/src/tiledb_array_write_dense_1.cc @@ -0,0 +1,97 @@ +/** + * @file tiledb_array_write_dense_1.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write to a dense array. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[] = + { + 0, 1, 2, 3, // Upper left tile + 4, 5, 6, 7, // Upper right tile + 8, 9, 10, 11, // Lower left tile + 12, 13, 14, 15 // Lower right tile + }; + size_t buffer_a2[] = + { + 0, 1, 3, 6, // Upper left tile + 10, 11, 13, 16, // Upper right tile + 20, 21, 23, 26, // Lower left tile + 30, 31, 33, 36 // Lower right tile + }; + const char buffer_var_a2[] = + "abbcccdddd" // Upper left tile + "effggghhhh" // Upper right tile + "ijjkkkllll" // Lower left tile + "mnnooopppp"; // Lower right tile + float buffer_a3[] = + { + 0.1, 0.2, 1.1, 1.2, 2.1, 2.2, 3.1, 3.2, // Upper left tile + 4.1, 4.2, 5.1, 5.2, 6.1, 6.2, 7.1, 7.2, // Upper right tile + 8.1, 8.2, 9.1, 9.2, 10.1, 10.2, 11.1, 11.2, // Lower left tile + 12.1, 12.2, 13.1, 13.2, 14.1, 14.2, 15.1, 15.2, // Lower right tile + }; + const void* buffers[] = { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3 }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2)-1, // No need to store the last '\0' character + sizeof(buffer_a3) + }; + + // Write to array + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_dense_2.cc b/examples/src/tiledb_array_write_dense_2.cc new file mode 100644 index 00000000..8b839294 --- /dev/null +++ b/examples/src/tiledb_array_write_dense_2.cc @@ -0,0 +1,99 @@ +/** + * @file tiledb_array_write_dense_2.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write to a dense array invoking the write function + * multiple times. This will have the same effect as program + * tiledb_array_write_1.cc. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/dense_arrays/my_array_A", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers - #1 + int buffer_a1[] = { 0, 1, 2, 3, 4, 5 }; + size_t buffer_a2[] = { 0, 1, 3, 6, 10, 11, 13, 16 }; + const char buffer_var_a2[] = "abbcccddddeffggghhhh"; + float* buffer_a3; + const void* buffers[] = { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3 }; + size_t buffer_sizes[] = + { + 6*sizeof(int), // 6 cels on a1 + 8*sizeof(size_t), 20, // 8 cells on a2 + 0 // no cells on a3 + }; + + // Write to array - #1 + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Prepare cell buffers - #2 + int buffer_a1_2[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + size_t buffer_a2_2[] = { 0, 1, 3, 6, 10, 11, 13, 16 }; + const char buffer_var_a2_2[] = "ijjkkkllllmnnooopppp"; + float buffer_a3_2[] = + { + 0.1, 0.2, 1.1, 1.2, 2.1, 2.2, 3.1, 3.2, // Upper left tile + 4.1, 4.2, 5.1, 5.2, 6.1, 6.2, 7.1, 7.2, // Upper right tile + 8.1, 8.2, 9.1, 9.2, 10.1, 10.2, 11.1, 11.2, // Lower left tile + 12.1, 12.2, 13.1, 13.2, 14.1, 14.2, 15.1, 15.2, // Lower right tile + }; + const void* buffers_2[] = { + buffer_a1_2, buffer_a2_2, buffer_var_a2_2, buffer_a3_2 }; + size_t buffer_sizes_2[] = + { + 10*sizeof(int), // 6 cels on a1 + 8*sizeof(size_t), 20, // 8 cells on a2 + 32*sizeof(float) // 16 cells on a3 (2 values each) + }; + + // Write to array - #2 + tiledb_array_write(tiledb_array, buffers_2, buffer_sizes_2); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_dense_A.cc b/examples/src/tiledb_array_write_dense_A.cc deleted file mode 100644 index 104ef946..00000000 --- a/examples/src/tiledb_array_write_dense_A.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - * File: tiledb_array_write_dense_A.cc - * - * Demonstrates how to write to dense array "workspace/A", in dense mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_A", - TILEDB_ARRAY_WRITE, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[16]; - float buffer_a2[16]; - const void* buffers[] = { buffer_a1, buffer_a2}; - size_t buffer_sizes[2] = { 16*sizeof(int) , 16*sizeof(float) }; - - /* Populate buffers with some arbitrary values. */ - for(int i=0; i<16; ++i) { - buffer_a1[i] = i; - buffer_a2[i] = 100.0 + i; - } - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_dense_var_A.cc b/examples/src/tiledb_array_write_dense_var_A.cc deleted file mode 100644 index 9a2fc428..00000000 --- a/examples/src/tiledb_array_write_dense_var_A.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - * File: tiledb_array_write_dense_A.cc - * - * Demonstrates how to write to dense array "workspace/A", in dense mode. - */ - -#include "c_api.h" -#include "cstring" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/dense_var_A", - TILEDB_ARRAY_WRITE, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - size_t buffer_a1[16] = {0, 3, 8, 11, 18, 21, 26, 28, 33, - 39, 42, 45, 50, 54, 60, 63}; - const char buffer_var_a1[] = - "aa\0bbbb\0cc\0dddddd\0ee\0ffff\0g\0hhhh\0iiiii\0jj\0" - "kk\0llll\0mmm\0nnnnn\0oo\0pp"; - - float buffer_a2[16]; - const void* buffers[] = { buffer_a1, buffer_var_a1, buffer_a2}; - size_t buffer_sizes[3] = { sizeof(buffer_a1), sizeof(buffer_var_a1), - sizeof(buffer_a2) }; - - /* Populate buffers with some arbitrary values. */ - for(int i=0; i<16; ++i) { - buffer_a2[i] = 100.0 + i; - } - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_sparse_1.cc b/examples/src/tiledb_array_write_sparse_1.cc new file mode 100644 index 00000000..e46ac004 --- /dev/null +++ b/examples/src/tiledb_array_write_sparse_1.cc @@ -0,0 +1,82 @@ +/** + * @file tiledb_array_write_sparse_1.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write to a sparse array. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + size_t buffer_a2[] = { 0, 1, 3, 6, 10, 11, 13, 16 }; + const char buffer_var_a2[] = "abbcccddddeffggghhhh"; + float buffer_a3[] = + { + 0.1, 0.2, 1.1, 1.2, 2.1, 2.2, 3.1, 3.2, + 4.1, 4.2, 5.1, 5.2, 6.1, 6.2, 7.1, 7.2 + }; + int64_t buffer_coords[] = { 1, 1, 1, 2, 1, 4, 2, 3, 3, 3, 3, 4, 4, 2, 3, 1 }; + const void* buffers[] = + { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3, buffer_coords }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2)-1, // No need to store the last '\0' character + sizeof(buffer_a3), + sizeof(buffer_coords) + }; + + // Write to array + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_sparse_2.cc b/examples/src/tiledb_array_write_sparse_2.cc new file mode 100644 index 00000000..a9fcb6c5 --- /dev/null +++ b/examples/src/tiledb_array_write_sparse_2.cc @@ -0,0 +1,107 @@ +/** + * @file tiledb_array_write_sparse_2.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write to a sparse array with two sorted batch writes. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_WRITE, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers - #1 + int buffer_a1[] = { 0, 1, 2 }; + size_t buffer_a2[] = { 0, 1, 3, 6, 10, 11, 13, 16 }; + const char buffer_var_a2[] = "abbcccddddeffggghhhh"; + float buffer_a3[] = + { + 0.1, 0.2, 1.1, 1.2, 2.1, 2.2, 3.1, 3.2, + 4.1, 4.2, 5.1, 5.2, 6.1, 6.2, 7.1, 7.2 + }; + int64_t buffer_coords[] = { 1, 1, 1, 2 }; + const void* buffers[] = + { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3, buffer_coords }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2)-1, // No need to store the last '\0' character + sizeof(buffer_a3), + sizeof(buffer_coords) + }; + + // Write to array - #1 + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Prepare cell buffers - #2 + int buffer_a1_2[] = { 3, 4, 5, 6, 7 }; + size_t* buffer_a2_2; + const char* buffer_var_a2_2; + float* buffer_a3_2; + int64_t buffer_coords_2[] = { 1, 4, 2, 3, 3, 3, 3, 4, 4, 2, 3, 1 }; + const void* buffers_2[] = + { + buffer_a1_2, + buffer_a2_2, + buffer_var_a2_2, + buffer_a3_2, + buffer_coords_2 }; + size_t buffer_sizes_2[] = + { + sizeof(buffer_a1_2), + 0, + 0, + 0, + sizeof(buffer_coords_2) + }; + + // Write to array - #2 + tiledb_array_write(tiledb_array, buffers_2, buffer_sizes_2); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_sparse_3.cc b/examples/src/tiledb_array_write_sparse_3.cc new file mode 100644 index 00000000..1469ec4b --- /dev/null +++ b/examples/src/tiledb_array_write_sparse_3.cc @@ -0,0 +1,82 @@ +/** + * @file tiledb_array_write_sparse_3.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write unsorted cells to a sparse array. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_WRITE_UNSORTED, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[] = { 7, 5, 0, 6, 4, 3, 1, 2 }; + size_t buffer_a2[] = { 0, 4, 6, 7, 10, 11, 15, 17 }; + const char buffer_var_a2[] = "hhhhffagggeddddbbccc"; + float buffer_a3[] = + { + 7.1, 7.2, 5.1, 5.2, 0.1, 0.2, 6.1, 6.2, + 4.1, 4.2, 3.1, 3.2, 1.1, 1.2, 2.1, 2.2 + }; + int64_t buffer_coords[] = { 3, 1, 3, 4, 1, 1, 4, 2, 3, 3, 2, 3, 1, 2, 1, 4 }; + const void* buffers[] = + { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3, buffer_coords }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2)-1, // No need to store the last '\0' character + sizeof(buffer_a3), + sizeof(buffer_coords) + }; + + // Write to array + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_sparse_4.cc b/examples/src/tiledb_array_write_sparse_4.cc new file mode 100644 index 00000000..bb7922af --- /dev/null +++ b/examples/src/tiledb_array_write_sparse_4.cc @@ -0,0 +1,105 @@ +/** + * @file tiledb_array_write_sparse_4.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write unsorted cells to a sparse array with two batch writes. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize array + TileDB_Array* tiledb_array; + tiledb_array_init( + tiledb_ctx, // Context + &tiledb_array, // Array object + "my_workspace/sparse_arrays/my_array_B", // Array name + TILEDB_ARRAY_WRITE_UNSORTED, // Mode + NULL, // Entire domain + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers - #1 + int buffer_a1[] = { 7, 5, 0 }; + size_t buffer_a2[] = { 0, 4, 6 }; + const char buffer_var_a2[] = "hhhhffa"; + float buffer_a3[] = { 7.1, 7.2, 5.1, 5.2, 0.1, 0.2 }; + int64_t buffer_coords[] = { 3, 1, 3, 4, 1, 1 }; + const void* buffers[] = + { buffer_a1, buffer_a2, buffer_var_a2, buffer_a3, buffer_coords }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), + sizeof(buffer_a2), + sizeof(buffer_var_a2)-1, // No need to store the last '\0' character + sizeof(buffer_a3), + sizeof(buffer_coords) + }; + + // Write to array - #1 + tiledb_array_write(tiledb_array, buffers, buffer_sizes); + + // Prepare cell buffers - #2 + int buffer_a1_2[] = { 6, 4, 3, 1, 2 }; + size_t buffer_a2_2[] = { 0, 3, 4, 8, 10 }; + const char buffer_var_a2_2[] = "gggeddddbbccc"; + float buffer_a3_2[] = + { 6.1, 6.2, 4.1, 4.2, 3.1, 3.2, 1.1, 1.2, 2.1, 2.2 }; + int64_t buffer_coords_2[] = { 4, 2, 3, 3, 2, 3, 1, 2, 1, 4 }; + const void* buffers_2[] = + { + buffer_a1_2, + buffer_a2_2, + buffer_var_a2_2, + buffer_a3_2, + buffer_coords_2 + }; + size_t buffer_sizes_2[] = + { + sizeof(buffer_a1_2), + sizeof(buffer_a2_2), + sizeof(buffer_var_a2_2)-1, // No need to store the last '\0' character + sizeof(buffer_a3_2), + sizeof(buffer_coords_2) + }; + + // Write to array - #2 + tiledb_array_write(tiledb_array, buffers_2, buffer_sizes_2); + + // Finalize array + tiledb_array_finalize(tiledb_array); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_array_write_sparse_A.cc b/examples/src/tiledb_array_write_sparse_A.cc deleted file mode 100644 index c379a960..00000000 --- a/examples/src/tiledb_array_write_sparse_A.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * File: tiledb_array_write_dense_A.cc - * - * Demonstrates how to write to dense array "workspace/A", in dense mode. - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_A", - TILEDB_ARRAY_WRITE, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[6]; - float buffer_a2[6]; - int64_t buffer_coords[12]; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_coords}; - size_t buffer_sizes[3] = { - 6*sizeof(int) , - 6*sizeof(float), - 12*sizeof(int64_t) }; - - /* Populate attribute buffers with some arbitrary values. */ - for(int i=0; i<6; ++i) { - buffer_a1[i] = i; - buffer_a2[i] = 100.0 + i; - } - - /* Populate coordinates buffer with some arbitrary values. */ - buffer_coords[0] = 1; buffer_coords[1] = 1; - buffer_coords[2] = 2; buffer_coords[3] = 1; - buffer_coords[4] = 2; buffer_coords[5] = 2; - buffer_coords[6] = 4; buffer_coords[7] = 2; - buffer_coords[8] = 3; buffer_coords[9] = 3; - buffer_coords[10] = 1; buffer_coords[11] = 4; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_sparse_unsorted_A.cc b/examples/src/tiledb_array_write_sparse_unsorted_A.cc deleted file mode 100644 index a3246f85..00000000 --- a/examples/src/tiledb_array_write_sparse_unsorted_A.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * File: tiledb_array_write_sparse_unsorted_A.cc - * - * Demonstrates how to write to sparse array "workspace/sparse_A", in - * in unsorted mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_A", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[6]; - float buffer_a2[6]; - int64_t buffer_coords[12]; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_coords}; - size_t buffer_sizes[3] = { - 6*sizeof(int) , - 6*sizeof(float), - 12*sizeof(int64_t) }; - - /* Populate attribute buffers with some arbitrary values. */ - for(int i=0; i<6; ++i) { - buffer_a1[i] = i; - buffer_a2[i] = 100.0 + i; - } - - /* Populate coordinates buffer with some arbitrary values. */ - buffer_coords[0] = 4; buffer_coords[1] = 2; - buffer_coords[2] = 1; buffer_coords[3] = 1; - buffer_coords[4] = 3; buffer_coords[5] = 3; - buffer_coords[6] = 2; buffer_coords[7] = 1; - buffer_coords[8] = 1; buffer_coords[9] = 4; - buffer_coords[10] = 2; buffer_coords[11] = 2; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_sparse_unsorted_var_A.cc b/examples/src/tiledb_array_write_sparse_unsorted_var_A.cc deleted file mode 100644 index 27924de4..00000000 --- a/examples/src/tiledb_array_write_sparse_unsorted_var_A.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * File: tiledb_array_write_sparse_unsorted_A.cc - * - * Demonstrates how to write to sparse array "workspace/sparse_A", in - * in unsorted mode. - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_var_A", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - int buffer_a1[6]; - float buffer_a2[6]; - int64_t buffer_coords[12]; - const void* buffers[] = { buffer_a1, buffer_a2, buffer_coords}; - size_t buffer_sizes[3] = { - 6*sizeof(int) , - 6*sizeof(float), - 12*sizeof(int64_t) }; - - /* Populate attribute buffers with some arbitrary values. */ - for(int i=0; i<6; ++i) { - buffer_a1[i] = i; - buffer_a2[i] = 100.0 + i; - } - - /* Populate coordinates buffer with some arbitrary values. */ - buffer_coords[0] = 4; buffer_coords[1] = 2; - buffer_coords[2] = 1; buffer_coords[3] = 1; - buffer_coords[4] = 3; buffer_coords[5] = 3; - buffer_coords[6] = 2; buffer_coords[7] = 1; - buffer_coords[8] = 1; buffer_coords[9] = 4; - buffer_coords[10] = 2; buffer_coords[11] = 2; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_array_write_sparse_var_A.cc b/examples/src/tiledb_array_write_sparse_var_A.cc deleted file mode 100644 index 702162a1..00000000 --- a/examples/src/tiledb_array_write_sparse_var_A.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * File: tiledb_array_write_dense_A.cc - * - * Demonstrates how to write to dense array "workspace/A", in dense mode. - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Initialize the array in WRITE mode. */ - TileDB_Array* tiledb_array; - tiledb_array_init( - tiledb_ctx, - &tiledb_array, - "workspace/sparse_var_A", - TILEDB_ARRAY_WRITE_UNSORTED, - NULL, // No range - entire domain - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ - size_t buffer_a1[6] = {0, 3, 8, 11, 18, 21 }; - const char buffer_var_a1[] = - "aa\0bbbb\0cc\0dddddd\0ee\0ffff"; - float buffer_a2[6]; - int64_t buffer_coords[12]; - const void* buffers[] = { buffer_a1, buffer_var_a1, buffer_a2, buffer_coords}; - size_t buffer_sizes[] = { - sizeof(buffer_a1) , - sizeof(buffer_var_a1), - sizeof(buffer_a2), - sizeof(buffer_coords) }; - - /* Populate attribute buffers with some arbitrary values. */ - for(int i=0; i<6; ++i) - buffer_a2[i] = 100.0 + i; - - /* Populate coordinates buffer with some arbitrary values. */ - buffer_coords[0] = 1; buffer_coords[1] = 1; - buffer_coords[2] = 2; buffer_coords[3] = 1; - buffer_coords[4] = 2; buffer_coords[5] = 2; - buffer_coords[6] = 4; buffer_coords[7] = 2; - buffer_coords[8] = 3; buffer_coords[9] = 3; - buffer_coords[10] = 1; buffer_coords[11] = 4; - - /* Write to array. */ - tiledb_array_write(tiledb_array, buffers, buffer_sizes); - - /* Finalize the array. */ - tiledb_array_finalize(tiledb_array); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_clear.cc b/examples/src/tiledb_clear.cc deleted file mode 100644 index 5bb962b2..00000000 --- a/examples/src/tiledb_clear.cc +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - tiledb_clear(tiledb_ctx, "workspace"); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_clear_delete_move.cc b/examples/src/tiledb_clear_delete_move.cc new file mode 100644 index 00000000..e4fabc2b --- /dev/null +++ b/examples/src/tiledb_clear_delete_move.cc @@ -0,0 +1,53 @@ +/** + * @file tiledb_clear_delete_move.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to clear, delete and move TileDB objects. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Clear an array + tiledb_clear(tiledb_ctx, "my_workspace/sparse_arrays/my_array_B"); + + // Delete a group + tiledb_delete(tiledb_ctx, "my_workspace/dense_arrays"); + + // Move a workspace + tiledb_move(tiledb_ctx, "my_workspace", "my_workspace_2"); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_delete.cc b/examples/src/tiledb_delete.cc deleted file mode 100644 index 15faa6b9..00000000 --- a/examples/src/tiledb_delete.cc +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - tiledb_delete(tiledb_ctx, "workspace_2"); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_group_create.cc b/examples/src/tiledb_group_create.cc deleted file mode 100644 index 3ff6c1f6..00000000 --- a/examples/src/tiledb_group_create.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* - * File: tiledb_array_read_dense_A.cc - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - // Create the workspace - tiledb_group_create(tiledb_ctx, "workspace/group"); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_ls.cc b/examples/src/tiledb_ls.cc index 3fa47d03..27997066 100644 --- a/examples/src/tiledb_ls.cc +++ b/examples/src/tiledb_ls.cc @@ -1,42 +1,83 @@ -/* - * Demonstrates how to read from dense array "workspace/A". +/** + * @file tiledb_list.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to explore the contents of a TileDB directory. */ #include "c_api.h" -#include +#include +#include -int main() { - /* Intialize context with the default configuration parameters. */ +int main(int argc, char** argv) { + // Sanity check + if(argc != 2) { + fprintf(stderr, "Usage: ./tiledb_list parent_dir\n"); + return -1; + } + + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - // Get workspaces - char* dirs[100]; - int dir_num = 100; - int dir_types[100]; - const char* parent_dir = "workspace"; + // Initialize variables + char* dirs[10]; + int dir_num = 10; + int dir_types[10]; for(int i=0; i +#include +#include int main() { - /* Intialize context with the default configuration parameters. */ + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - // Get workspaces - char* workspaces[100]; - int workspace_num = 100; - for(int i=0; i int main() { - /* Intialize context with the default configuration parameters. */ + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - /* Initialize the array in WRITE mode. */ + // Initialize metadata TileDB_Metadata* tiledb_metadata; tiledb_metadata_init( - tiledb_ctx, - &tiledb_metadata, - "~/.tiledb/master_catalog", - TILEDB_METADATA_WRITE, - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL + tiledb_ctx, // Context + &tiledb_metadata, // Metadata object + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + TILEDB_METADATA_WRITE, // Mode + NULL, // All attributes + 0); - /* Consolidate metadata. */ + // Consolidate metadata tiledb_metadata_consolidate(tiledb_metadata); - /* Finalize the metadata. */ + // Finalize metadata tiledb_metadata_finalize(tiledb_metadata); - /* Finalize context. */ + // Finalize context tiledb_ctx_finalize(tiledb_ctx); return 0; diff --git a/examples/src/tiledb_metadata_create.cc b/examples/src/tiledb_metadata_create.cc index 3529785b..b8183408 100644 --- a/examples/src/tiledb_metadata_create.cc +++ b/examples/src/tiledb_metadata_create.cc @@ -1,42 +1,82 @@ -/* +/** + * @file tiledb_metadata_create.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It creates a metadata object. */ #include "c_api.h" -#include -#include int main() { - /* Initialize context with the default configuration parameters. */ + // Initialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); + // Prepare parameters for metadata schema + const char* metadata_name = "my_workspace/sparse_arrays/my_array_B/meta"; + const char* attributes[] = { "a1", "a2" }; // Two attributes + const int cell_val_num[] = + { + 1, // a1 + TILEDB_VAR_NUM // a2 + }; + const int compression[] = + { + TILEDB_GZIP, // a1 + TILEDB_GZIP, // a2 + TILEDB_NO_COMPRESSION // TILEDB_KEY + }; + const int types[] = + { + TILEDB_INT32, // a1 + TILEDB_CHAR // a2 + }; + // Set metadata schema TileDB_MetadataSchema metadata_schema; - const char* attributes[] = { "a1", "a2" }; - const int types[] = { TILEDB_INT32, TILEDB_FLOAT32 }; tiledb_metadata_set_schema( - // The array schema struct - &metadata_schema, - // Array name - "workspace/meta_A", - // Attributes - attributes, - // Number of attributes - 2, - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - NULL, - // Capacity - 4, - // Compression - NULL + &metadata_schema, // Metadata schema struct + metadata_name, // Metadata name + attributes, // Attributes + 2, // Number of attributes + 4, // Capacity + cell_val_num, // Number of cell values per attribute + compression, // Compression + types // Types ); - /* Create the array. */ + // Create metadata tiledb_metadata_create(tiledb_ctx, &metadata_schema); - /* Finalize context. */ + // Free metadata schema + tiledb_metadata_free_schema(&metadata_schema); + + // Finalize context tiledb_ctx_finalize(tiledb_ctx); return 0; diff --git a/examples/src/tiledb_metadata_iterator.cc b/examples/src/tiledb_metadata_iterator.cc new file mode 100644 index 00000000..584e129b --- /dev/null +++ b/examples/src/tiledb_metadata_iterator.cc @@ -0,0 +1,87 @@ +/** + * @file tiledb_metadata_iterator.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to use a metadata iterator. + */ + +#include "c_api.h" +#include + +int main() { + /* Intialize context with the default configuration parameters. */ + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Subset over the attributes + const char* attributes[] = { TILEDB_KEY }; + + // Prepare cell buffers + size_t buffer_key[8]; + char buffer_key_var[500]; + void* buffers[] = { buffer_key, buffer_key_var }; + size_t buffer_sizes[] = { sizeof(buffer_key), sizeof(buffer_key_var) }; + + // Initialize metadata iterator + TileDB_MetadataIterator* tiledb_metadata_iterator; + tiledb_metadata_iterator_init( + tiledb_ctx, // Context + &tiledb_metadata_iterator, // Metadata iterator + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + attributes, // Attributes + 1, // Number of attributes + buffers, // Buffers for internal use + buffer_sizes); // Sizes of buffers + + // Iterate over the metadata + const char* key; + size_t key_size; + while(!tiledb_metadata_iterator_end(tiledb_metadata_iterator)) { + // Get value + tiledb_metadata_iterator_get_value( + tiledb_metadata_iterator, // Metadata iterator + 0, // Attribute id + (const void**) &key, // Key + &key_size); // Key size + + // Print only if it is not empty + if(key[0] != TILEDB_EMPTY_CHAR) + printf("%s\n", key); + + // Advance iterator + tiledb_metadata_iterator_next(tiledb_metadata_iterator); + } + + // Finalize metadata iterator + tiledb_metadata_iterator_finalize(tiledb_metadata_iterator); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_metadata_iterator_read.cc b/examples/src/tiledb_metadata_iterator_read.cc deleted file mode 100644 index 9df25112..00000000 --- a/examples/src/tiledb_metadata_iterator_read.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - /* Subset over attribute "a1". */ - //const char* attributes[] = { "a1" }; - const char* attributes[] = { TILEDB_KEY }; - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[8]; - float buffer_a2[8]; - size_t buffer_key[8]; - char buffer_key_var[500]; - //void* buffers[] = { buffer_a1 }; - //size_t buffer_sizes[] = { sizeof(buffer_a1) }; - void* buffers[] = { buffer_key, buffer_key_var }; - size_t buffer_sizes[] = { sizeof(buffer_key), sizeof(buffer_key_var) }; - - /* Initialize the array in READ mode. */ - TileDB_MetadataIterator* tiledb_metadata_iterator; - tiledb_metadata_iterator_init( - tiledb_ctx, - &tiledb_metadata_iterator, - "~/.tiledb/master_catalog", - attributes, - 1, - buffers, - buffer_sizes); - - /* Read from array. */ - const char* key; - size_t key_size, a_size; - const float* a; - - while(!tiledb_metadata_iterator_end(tiledb_metadata_iterator)) { - tiledb_metadata_iterator_get_value(tiledb_metadata_iterator, 0, (const void**) &key, &key_size); - if(key[0] == TILEDB_EMPTY_CHAR) - std::cout << "EMPTY\n"; - else - std::cout << key << " " << key_size << "\n"; - tiledb_metadata_iterator_next(tiledb_metadata_iterator); - } - - /* Finalize the metadata iterator. */ - tiledb_metadata_iterator_finalize(tiledb_metadata_iterator); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_metadata_load_schema.cc b/examples/src/tiledb_metadata_load_schema.cc deleted file mode 100644 index 8fd5df82..00000000 --- a/examples/src/tiledb_metadata_load_schema.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Demonstrates how to create a dense array, called "dense_A". - */ - -#include "c_api.h" -#include - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - // Get array schema - TileDB_MetadataSchema metadata_schema; - tiledb_metadata_load_schema(tiledb_ctx, "workspace/meta_A", &metadata_schema); - - // Print schema - std::cout << "Metadata name:\n"; - std::cout << metadata_schema.metadata_name_ << "\n"; - std::cout << "Attribute num:\n"; - std::cout << metadata_schema.attribute_num_ << "\n"; - std::cout << "Attributes:\n"; - for(int i=0; i + +// Prints some schema info (you can enhance this to print the entire schema) +void print_some_metadata_schema_info( + const TileDB_MetadataSchema* metadata_schema); + +int main() { + /* Intialize context with the default configuration parameters. */ + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // ----- Get schema without metadata initialization ----- // + + // Load metadata schema when the metadata object is not initialized + TileDB_MetadataSchema metadata_schema; + tiledb_metadata_load_schema( + tiledb_ctx, // Context + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + &metadata_schema); // Metadata schema struct + + // Print some metadata schema info + print_some_metadata_schema_info(&metadata_schema); + + // Free metadata schema + tiledb_metadata_free_schema(&metadata_schema); + + // ----- Get schema after metadata initialization ----- // + + // Initialize metadata + TileDB_Metadata* tiledb_metadata; + tiledb_metadata_init( + tiledb_ctx, // Context + &tiledb_metadata, // Array object + "my_workspace/sparse_arrays/my_array_B/meta", // Array name + TILEDB_METADATA_READ, // Mode + NULL, // Attributes (all) + 0); // Number of attributes + + // Get metadata schema when the metadata object is initialized + tiledb_metadata_get_schema(tiledb_metadata, &metadata_schema); + + // Print some schema info + print_some_metadata_schema_info(&metadata_schema); + + // Free metadata schema + tiledb_metadata_free_schema(&metadata_schema); + + // Finalize metadata + tiledb_metadata_finalize(tiledb_metadata); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} + +void print_some_metadata_schema_info( + const TileDB_MetadataSchema* metadata_schema) { + printf("Metadata name: %s\n", metadata_schema->metadata_name_); + printf("Attributes: "); + for(int i=0; iattribute_num_; ++i) + printf("%s ", metadata_schema->attributes_[i]); + printf("\n"); +} diff --git a/examples/src/tiledb_metadata_read.cc b/examples/src/tiledb_metadata_read.cc index 8de20c38..2cc3fe43 100644 --- a/examples/src/tiledb_metadata_read.cc +++ b/examples/src/tiledb_metadata_read.cc @@ -1,38 +1,107 @@ -/* - * Demonstrates how to read from dense array "workspace/A". +/** + * @file tiledb_metadata_read.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to read from metadata. */ #include "c_api.h" -#include +#include -int main() { - /* Intialize context with the default configuration parameters. */ +int main(int argc, char** argv) { + // Sanity check + if(argc != 2) { + fprintf(stderr, "Usage: ./tiledb_metadata_read key\n"); + return -1; + } + + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - /* Subset over attribute "a1". */ - const char* attributes[] = { "a1" }; + // Subset over attributes + const char* attributes[] = { "a1", "a2" }; - /* Initialize the array in READ mode. */ + // Initialize metadata TileDB_Metadata* tiledb_metadata; tiledb_metadata_init( - tiledb_ctx, - &tiledb_metadata, - "workspace/meta_A", - TILEDB_METADATA_READ, - attributes, - 1); - - /* Prepare cell buffers for attribute "a1". */ - int buffer_a1[10]; - void* buffers[] = { buffer_a1 }; - size_t buffer_sizes[1] = { sizeof(buffer_a1) }; - - /* Read from array. */ - tiledb_metadata_read(tiledb_metadata, "key1", buffers, buffer_sizes); - std::cout << buffer_a1[0] << "\n"; - tiledb_metadata_read(tiledb_metadata, "key2", buffers, buffer_sizes); - std::cout << buffer_a1[0] << "\n"; + tiledb_ctx, // Context + &tiledb_metadata, // Metadata object + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + TILEDB_METADATA_READ, // Mode + attributes, // Attributes + 2); // Number of attributes + + // Prepare cell buffers + int buffer_a1[1]; + size_t buffer_a2[1]; + char buffer_var_a2[2]; + void* buffers[] = + { + buffer_a1, // a1 + buffer_a2, buffer_var_a2 // a2 + }; + size_t buffer_sizes[] = + { + sizeof(buffer_a1), // a1 + sizeof(buffer_a2), sizeof(buffer_var_a2) // a2 + }; + + + // Read from metadata + tiledb_metadata_read(tiledb_metadata, argv[1], buffers, buffer_sizes); + + // Check existence + if(buffer_sizes[0] == 0 && !tiledb_metadata_overflow(tiledb_metadata, 0)) { + fprintf(stderr, "Key '%s' does not exist in the metadata!\n", argv[1]); + return -1; + } + + // Check overflow for a2 + if(buffer_sizes[2] == 0 && tiledb_metadata_overflow(tiledb_metadata, 1)) { + fprintf(stderr, "Reading value on attribute 'a2' for key '%s' resulted in " + "a buffer overflow!\n", argv[1]); + return -1; + } + + // Check if deleted + if(static_cast(buffers[0])[0] == TILEDB_EMPTY_INT32) { + fprintf(stderr, "Key '%s' has been deleted!\n", argv[1]); + return -1; + } + + // Print attribute values + printf( + "%s: a1=%d, a2=%.*s\n", + argv[1], + static_cast(buffers[0])[0], + buffer_sizes[2], + static_cast(buffers[2])); /* Finalize the array. */ tiledb_metadata_finalize(tiledb_metadata); diff --git a/examples/src/tiledb_metadata_update.cc b/examples/src/tiledb_metadata_update.cc new file mode 100644 index 00000000..398cfc99 --- /dev/null +++ b/examples/src/tiledb_metadata_update.cc @@ -0,0 +1,89 @@ +/** + * @file tiledb_metadata_update.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to modify or delete a metadata item. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Initialize metadata + TileDB_Metadata* tiledb_metadata; + tiledb_metadata_init( + tiledb_ctx, // Context + &tiledb_metadata, // Metadata object + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + TILEDB_METADATA_WRITE, // Mode + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers + int buffer_a1[] = { 100, TILEDB_EMPTY_INT32 }; + size_t buffer_a2[] = { 0, 1 }; + char buffer_var_a2[] = { 'A', TILEDB_EMPTY_CHAR }; + char keys[] = "k1\0k2"; + size_t buffer_keys[] = { 0, 3 }; + char buffer_var_keys[] = + { + 'k', '1', '\0', // k1 modified key value + TILEDB_EMPTY_CHAR // k2 deleted value + }; + const void* buffers[] = + { + buffer_a1, // a1 + buffer_a2, buffer_var_a2, // a2 + buffer_keys, buffer_var_keys // TILEDB_KEY + }; + size_t buffer_sizes[] = { + sizeof(buffer_a1), // a1 + sizeof(buffer_a2), sizeof(buffer_var_a2), // a2 + sizeof(buffer_keys), sizeof(buffer_var_keys) // TILEDB_KEY + }; + size_t keys_size = sizeof(keys); + + // Write metadata + tiledb_metadata_write( + tiledb_metadata, // Metadata object + keys, // Keys + keys_size, // Keys size + buffers, // Attribute buffers + buffer_sizes); // Attribute buffer sizes + + // Finalize the metadata + tiledb_metadata_finalize(tiledb_metadata); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/examples/src/tiledb_metadata_write.cc b/examples/src/tiledb_metadata_write.cc index 09c56de4..0710854b 100644 --- a/examples/src/tiledb_metadata_write.cc +++ b/examples/src/tiledb_metadata_write.cc @@ -1,45 +1,83 @@ -/* - * File: tiledb_array_write_dense_A.cc +/** + * @file tiledb_metadata_write.cc + * + * @section LICENSE + * + * The MIT License * - * Demonstrates how to write to dense array "workspace/A", in dense mode. + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It shows how to write metadata. */ #include "c_api.h" -#include int main() { - /* Intialize context with the default configuration parameters. */ + // Intialize context with the default configuration parameters TileDB_CTX* tiledb_ctx; tiledb_ctx_init(&tiledb_ctx, NULL); - /* Initialize the metadata in WRITE mode. */ + // Initialize metadata TileDB_Metadata* tiledb_metadata; tiledb_metadata_init( - tiledb_ctx, - &tiledb_metadata, - "workspace/meta_A", - TILEDB_METADATA_WRITE, - NULL, // No projection - all attributes - 0); // Meaningless when "attributes" is NULL - - /* Prepare cell buffers for attributes "a1" and "a2". */ + tiledb_ctx, // Context + &tiledb_metadata, // Metadata object + "my_workspace/sparse_arrays/my_array_B/meta", // Metadata name + TILEDB_METADATA_WRITE, // Mode + NULL, // All attributes + 0); // Number of attributes + + // Prepare cell buffers int buffer_a1[] = { 1, 2, 3 }; - float buffer_a2[] = { 1.0, 1.1, 1.2 }; - char buffer_keys[] = "key1\0key2\0key3"; - const void* buffers[] = { buffer_a1, buffer_a2}; + size_t buffer_a2[] = { 0, 1, 3 }; + char buffer_var_a2[] = "abbccc"; + size_t buffer_keys[] = { 0, 3, 6 }; + char buffer_var_keys[] = "k1\0k2\0k3"; + const void* buffers[] = + { + buffer_a1, // a1 + buffer_a2, buffer_var_a2, // a2 + buffer_keys, buffer_var_keys // TILEDB_KEY + }; size_t buffer_sizes[] = { - sizeof(buffer_a1), - sizeof(buffer_a2), + sizeof(buffer_a1), // a1 + sizeof(buffer_a2), sizeof(buffer_var_a2), // a2 + sizeof(buffer_keys), sizeof(buffer_var_keys) // TILEDB_KEY }; - size_t keys_size = sizeof(buffer_keys); + size_t keys_size = sizeof(buffer_var_keys); - /* Write to metadata. */ - tiledb_metadata_write(tiledb_metadata, buffer_keys, keys_size, buffers, buffer_sizes); + // Write metadata + tiledb_metadata_write( + tiledb_metadata, // Metadata object + buffer_var_keys, // Keys + keys_size, // Keys size + buffers, // Attribute buffers + buffer_sizes); // Attribute buffer sizes - /* Finalize the metadata. */ + // Finalize the metadata tiledb_metadata_finalize(tiledb_metadata); - /* Finalize context. */ + // Finalize context tiledb_ctx_finalize(tiledb_ctx); return 0; diff --git a/examples/src/tiledb_move.cc b/examples/src/tiledb_move.cc deleted file mode 100644 index e4af8733..00000000 --- a/examples/src/tiledb_move.cc +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - tiledb_move(tiledb_ctx, "workspace_2", "workspace"); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_workspace_create.cc b/examples/src/tiledb_workspace_create.cc deleted file mode 100644 index 660e7bcd..00000000 --- a/examples/src/tiledb_workspace_create.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* - * File: tiledb_array_read_dense_A.cc - * - * Demonstrates how to read from dense array "workspace/A". - */ - -#include "c_api.h" - -int main() { - /* Intialize context with the default configuration parameters. */ - TileDB_CTX* tiledb_ctx; - tiledb_ctx_init(&tiledb_ctx, NULL); - - // Create the workspace - tiledb_workspace_create(tiledb_ctx, "workspace_2"); - - /* Finalize context. */ - tiledb_ctx_finalize(tiledb_ctx); - - return 0; -} diff --git a/examples/src/tiledb_workspace_group_create.cc b/examples/src/tiledb_workspace_group_create.cc new file mode 100644 index 00000000..22ef5359 --- /dev/null +++ b/examples/src/tiledb_workspace_group_create.cc @@ -0,0 +1,53 @@ +/** + * @file tiledb_workspace_group_create.cc + * + * @section LICENSE + * + * The MIT License + * + * @copyright Copyright (c) 2016 MIT and Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * It creates a workspace and two groups. + */ + +#include "c_api.h" + +int main() { + // Intialize context with the default configuration parameters + TileDB_CTX* tiledb_ctx; + tiledb_ctx_init(&tiledb_ctx, NULL); + + // Create a workspace + tiledb_workspace_create(tiledb_ctx, "my_workspace"); + + // Create a group in the worskpace + tiledb_group_create(tiledb_ctx, "my_workspace/dense_arrays"); + + // Create two groups in the worskpace + tiledb_group_create(tiledb_ctx, "my_workspace/sparse_arrays"); + + // Finalize context + tiledb_ctx_finalize(tiledb_ctx); + + return 0; +} diff --git a/test/src/array/array_schema_spec.cc b/test/src/array/array_schema_spec.cc index a65cd1b6..ec8f5165 100644 --- a/test/src/array/array_schema_spec.cc +++ b/test/src/array/array_schema_spec.cc @@ -25,7 +25,7 @@ * to/from the array storage */ -#include "gtest/gtest.h" +#include #include #include "c_api.h" @@ -87,12 +87,20 @@ int ArraySchemaTest::create_dense_array() { attributes, // Number of attributes 1, + // Capacity + 1000, + // Cell order + TILEDB_COL_MAJOR, + // Number of cell values per attribute (NULL means 1 everywhere) + NULL, + // Compression + compression, + // Dense array + 1, // Dimensions dimensions, // Number of dimensions 2, - // Dense array - 1, // Domain domain, // Domain length in bytes @@ -101,18 +109,10 @@ int ArraySchemaTest::create_dense_array() { tile_extents, // Tile extents in bytes 10*sizeof(int64_t), - // Types - types, - // Number of cell values per attribute (NULL means 1 everywhere) - NULL, - // Cell order - TILEDB_COL_MAJOR, // Tile order (0 means ignore in sparse arrays and default in dense) 0, - // Capacity - 1000, - // Compression - compression + // Types + types ); /* Create the array. */ diff --git a/test/src/c_api/c_api_spec.cc b/test/src/c_api/c_api_spec.cc index 7cdce077..1c65c4d6 100644 --- a/test/src/c_api/c_api_spec.cc +++ b/test/src/c_api/c_api_spec.cc @@ -25,7 +25,7 @@ * dense and sparse TileDB arrays via the C API */ -#include "gtest/gtest.h" +#include #include "c_api.h" #include #include @@ -100,7 +100,6 @@ class TileDBAPITest: public testing::Test { int ret = system(command.c_str()); } }; - /** * Generate a test buffer to full up the dense array where * each cell value = row index * total number of columns + col index @@ -118,7 +117,7 @@ int **TileDBAPITest::generate_buffer(const int dim0, const int dim1) { /** * Create the test 100x100 dense array with tile sizes = 10x10 - */ +**/ int TileDBAPITest::create_dense_array( const long dim0_tile_extent, const long dim1_tile_extent, @@ -144,19 +143,19 @@ int TileDBAPITest::create_dense_array( arrayName.c_str(), attributes, attribute_num, + capacity, + TILEDB_ROW_MAJOR, + NULL, + compression, + dense, dimensions, ARRAY_RANK, - dense, domain, 4*sizeof(int64_t), tile_extents, 2*sizeof(int64_t), - types, - NULL, - TILEDB_ROW_MAJOR, 0, - capacity, - compression); + types); // Create the array int ret = tiledb_array_create(tiledb_ctx, &schema); @@ -186,7 +185,7 @@ int TileDBAPITest::write_dense_array( tiledb_ctx, &tiledb_array, arrayName.c_str(), - TILEDB_WRITE, + TILEDB_ARRAY_WRITE, NULL, // No range - entire domain NULL, // No projection - all attributes 0); // Meaningless when "attributes" is NULL @@ -233,7 +232,7 @@ int TileDBAPITest::update_dense_array( size_t buffer_sizes[2]) { /* Subset over attribute "a1" and the coordinates. */ - const char* attributes[] = { "ATTR_INT32", TILEDB_COORDS_NAME }; + const char* attributes[] = { "ATTR_INT32", TILEDB_COORDS }; /* Initialize the array in WRITE mode. */ TileDB_Array* tiledb_array; @@ -241,7 +240,7 @@ int TileDBAPITest::update_dense_array( tiledb_ctx, &tiledb_array, arrayName.c_str(), - TILEDB_WRITE_UNSORTED, + TILEDB_ARRAY_WRITE_UNSORTED, NULL, // No range - entire domain attributes, // No projection - all attributes 2); // Meaningless when "attributes" is NULL @@ -308,7 +307,7 @@ int * TileDBAPITest::read_dense_array( tiledb_ctx, &tiledb_array, arrayName.c_str(), - TILEDB_READ, + TILEDB_ARRAY_READ, range, attributes, 1); @@ -376,7 +375,6 @@ bool check_buffer( return fail; } - TEST_F(TileDBAPITest, DenseArrayRandomUpdates) { int64_t dim0 = 100;