Skip to content

Commit

Permalink
Merge pull request #1 from namnguyen1405/release_version_1.0.0
Browse files Browse the repository at this point in the history
Release DynamoDB FDW version 1.0.0
  • Loading branch information
t-hiroshige authored Oct 28, 2021
2 parents 2b8e4a8 + ebd186d commit cd27512
Show file tree
Hide file tree
Showing 56 changed files with 31,532 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated subdirectories
/log/
/results/
/tmp_check/
*.o
*.so
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
DynamoDB Foreign Data Wrapper for PostgreSQL

Copyright (c) 2021, TOSHIBA Corporation

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement is
hereby granted, provided that the above copyright notice and this paragraph and
the following two paragraphs appear in all copies.

IN NO EVENT SHALL TOSHIBA CORPORATION BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
TOSHIBA CORPORATION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

TOSHIBA CORPORATION SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
TOSHIBA CORPORATION HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
DIRJANSSON = ./jansson
OBJS_JANSSON = $(DIRJANSSON)/dump.o \
$(DIRJANSSON)/error.o \
$(DIRJANSSON)/hashtable.o \
$(DIRJANSSON)/hashtable_seed.o \
$(DIRJANSSON)/load.o \
$(DIRJANSSON)/memory.o \
$(DIRJANSSON)/pack_unpack.o \
$(DIRJANSSON)/strbuffer.o \
$(DIRJANSSON)/strconv.o \
$(DIRJANSSON)/utf.o \
$(DIRJANSSON)/value.o

JANSSON_CFLAGS = -DHAVE_STDINT_H=1 -Wno-suggest-attribute=format

MODULE_big = dynamodb_fdw
OBJS = $(OBJS_JANSSON) shippable.o deparse.o dynamodb_query.o dynamodb_impl.o dynamodb_fdw.o connection.o option.o

PGFILEDESC = "dynamodb_fdw - foreign data wrapper for DynamoDB"

SHLIB_LINK = -lm -lstdc++ -laws-cpp-sdk-core -laws-cpp-sdk-dynamodb

EXTENSION = dynamodb_fdw
DATA = dynamodb_fdw--1.0.sql

REGRESS = server_options connection_validation pushdown extra/delete extra/insert extra/json extra/jsonb extra/select extra/update

# EXTRA_CLEAN = sql/parquet_fdw.sql expected/parquet_fdw.out

# dynamodb_impl.cpp requires C++ 11.
PG_CFLAGS += -I$(DIRJANSSON) $(JANSSON_CFLAGS)
PG_CXXFLAGS += -I$(DIRJANSSON) $(JANSSON_CFLAGS) -std=c++11
# override PG_CXXFLAGS and PG_CFLAGS
ifdef CCFLAGS
override PG_CXXFLAGS += $(CCFLAGS)
override PG_CFLAGS += $(CCFLAGS)
endif

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

# PostgreSQL below 11 does not automatically add -fPIC or equivalent to C++
# flags when building a shared library, have to do it here explicitely.
ifeq ($(shell test $(VERSION_NUM) -lt 110000; echo $$?), 0)
override CXXFLAGS += $(CFLAGS_SL)
endif
else
subdir = contrib/dynamodb_fdw
top_builddir = ../..

# PostgreSQL uses link time optimization option which may break compilation
# (this happens on travis-ci). Redefine COMPILE.cxx.bc without this option.
COMPILE.cxx.bc = $(CLANG) -xc++ -Wno-ignored-attributes $(BITCODE_CXXFLAGS) $(CPPFLAGS) -emit-llvm -c

include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk

# A hurdle to use common compiler flags when building bytecode from C++
# files. should be not unnecessary, but src/Makefile.global omits passing those
# flags for an unnknown reason.
%.bc : %.cpp
$(COMPILE.cxx.bc) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
endif
94 changes: 93 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
# dynamodb_fdw
# DynamoDB Foreign Data Wrapper for PostgreSQL

This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for DynamoDB.

## 1. Requirement
1. AWS C++ SDK<br>
DynamoDB FDW uses the APIs provided by AWS C++ SDK to connect and execute query on DynamoDB.<br>
It requires gcc version 4.9.0 and above to be able to use and compile.<br>
It also requires 3rd party libraries: libcurl, openssl, libuuid, pulseaudio-libs. <br>
2. Java Runtime Environment (JRE) version 8.x or newer<br>
If using DynamoDB local, JRE 8.x or newer is required.<br>
## 2. Installation guide
This section describle how to install required library on CentOS 7
1. AWS C++ SDK<br>
Download and follow the Amazon developer guide.
<pre>https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/setup-linux.html</pre>

2. Java Runtime Environment (JRE) version 8.x or newer
<pre>
$ sudo yum install java-1.8.0-openjdk-devel.x86_64</pre>
3. Build and install PostgreSQL: from PostgreSQL directory
<pre>
./configure
$ make
$ make install</pre>
4. Build and install DynamoDB FDW:
clone source code under PostgreSQL/contrib/
<pre>
$ make
$ make install</pre>
## 3. FDW options
DynamoDB FDW supports the following options:<br>

| No | Option name |Context | Required | Description |
|----|-------------|--------|----------|-------------|
|1 |endpoint|SERVER|Optional|The URL of the entry point for an AWS web service. If user does not specify this option, the endpoint is set to "http://localhost:8000" by default. It is required for AWS DynamoDB and optional for DynamoDB local.
|2 |user|USER MAPPING|Optional|The user credential to connect to DynamoDB. It is required for AWS DynamoDB and optional for DynamoDB local.
|3 |password|USER MAPPING|Optional|The password credential to connect to DynamoDB. It is required for AWS DynamoDB and optional for DynamoDB local.
|4 |partition_key|FOREIGN TABLE|Optional|The column name of the partition key of DynamoDB table.
|5 |sort_key|FOREIGN TABLE|Optional|The column name of the sort key of DynamoDB table.
|6 |table_name|FOREIGN TABLE|Optional|The corresponding table name in DynamoDB.
|7 |column_name|ATTRIBUTE|Optional|The corresponding column name in DynamoDB.
## 5. Usage
* Load extension first time after install:
<pre>CREATE EXTENSION dynamodb_fdw;</pre>

* Create server object:
<pre>CREATE SERVER dynamodb_svr FOREIGN DATA WRAPPER dynamodb_fdw OPTIONS (endpoint 'http://localhost:8000');</pre>

* Create user mapping:
<pre>CREATE USER MAPPING FOR CURRENT_USER SERVER dynamodb_svr OPTIONS (user 'user1', password 'pass');</pre>

* Create foreign table:
<pre>CREATE FOREIGN TABLE frtbl (c1 int, c2 text, c3 jsonb) SERVER dynamodb_svr OPTIONS (table_name 'table1');</pre>

* Start executing query:
<pre>SELECT * FROM frtbl;</pre>

## 6. Features
* Support SELECT feature to get data from DynamoDB. DynamoDB FDW supports selecting columns or nested attribute object (using -> or ->> operator)<br>
* Support INSERT feature.
* Support UPDATE feature using foreign modify.
* Support DELETE feature using foreign modify.
* Support push down WHERE clause (including nested attribute object).
* Support push down function SIZE of DynamoDB.

## 7. Limitations
* Does not support List type of DynamoDB.
* Only support SELECT the Binary type of DynamoDB. Does not support WHERE clause, INSERT, UPDATE statement with Binary type of DynamoDB.
* For DynamoDB, 2 records can have the same attribute name but different data type. However, DynamoDB FDW does not support that case. User need to avoid using that case.
* Does not push down WHERE condition when it compares array constant.<br>
For example: `SELECT * FROM array_test WHERE array_n < '{1232, 5121, 8438, 644, 83}';` is not pushed down.
* Does not push down WHERE condition when it contains text comparison using "<, <=, >=, >" operators.<br>
For example: `SELECT * FROM WHERE name > '@#!S';` is not pushed down.
* Does not push down when selecting multiple attributes with the same name.<br>
For example: `SELECT name, friends->'class_info'->'name' FROM students;`
* Does not push down overlap document path. <br>
For example: `SELECT friends->'class_info', friends->'class_info'->'name' FROM students;`
## 8. Notes
* For string set and number set of DynamoDB, the values in the set are sorted from smallest to largest automatically.<br>
Therefore, if you want to access to the element of array, it will return the different value compared to insert value.<br>
For example, you insert `<<3,2,1>>` into DynamoDB. DynamoDB will sort and store it as `<<1,2,3>>`.<br>
If you want to select element `[1]` of the set, it will return 1.
* DynamoDB does not support NULL as element of string set or number set.<br>
Therefore, when user input NULL as element of array, the default value (0 for number, empty string for text) will be inserted into DynamoDB.<br>
For example, user input `array[1,2,null,4]`, the values inserted into DynamoDB will be `[1, 2, 0, 4]`.<br>
User input `array['one','two',null,'four']`, the values inserted into DynamoDB will be `['one', 'two', '', 'four']`.
* If an attribute of Map type does not exist, the condition `xxx IS NULL` will always return false.

## 9. License
Copyright and license information can be found in the file [`LICENSE`][1].

[1]: LICENSE
Loading

0 comments on commit cd27512

Please sign in to comment.