Skip to content

Commit

Permalink
Support postgres 13 (#31)
Browse files Browse the repository at this point in the history
* Support Postgres 13b2
* Fix Bugs
** WHERE false not support in SQLite
  - Root cause: sqlite_prepare_wrapper not support WHERE (false)
  - Solution: Change WHERE (false) to WHERE (0) --> sqlite_prepare_wrapper is OK
** Return error when SQLite returning infinity value
  - sqlite_fdw forwards the infinity value from SQLite
    It should return error.
  • Loading branch information
lamduongngoc authored Sep 24, 2020
1 parent 478ee4c commit 1f64853
Show file tree
Hide file tree
Showing 42 changed files with 24,752 additions and 1,490 deletions.
71 changes: 57 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
def NODE_NAME = 'AWS_Instance_CentOS'
def BRANCH_NAME = 'Branch [' + env.BRANCH_NAME + ']'
def MAIL_TO = '$DEFAULT_RECIPIENTS'
def MAIL_SUBJECT = '[CI PGSpider] SQLite FDW Test FAILED ' + BRANCH_NAME
def BUILD_INFO = 'Jenkins job: ' + env.BUILD_URL
def MAIL_TO='$DEFAULT_RECIPIENTS'
def MAIL_SUBJECT='[CI PGSpider] SQLite FDW Test FAILED ' + BRANCH_NAME
def SQLITE_FDW_URL = 'https://github.com/pgspider/sqlite_fdw.git'
def BRANCH_NAME = 'Branch [' + env.BRANCH_NAME + ']'

def retrySh(String shCmd) {
def MAX_RETRY = 10
Expand All @@ -12,10 +11,10 @@ def retrySh(String shCmd) {
for (int i = 0; i < MAX_RETRY; i++) {
status = sh(returnStatus: true, script: shCmd)
if (status == 0) {
echo "SUCCESS: "+shCmd
echo "SUCCESS: " + shCmd
break
} else {
echo "RETRY: "+shCmd
echo "RETRY: " + shCmd
sleep 5
}
}
Expand All @@ -31,35 +30,76 @@ pipeline {
label NODE_NAME
}
}
options {
gitLabConnection('GitLabConnection')
}
triggers {
pollSCM('H/30 * * * *')
gitlab(
triggerOnPush: true,
triggerOnMergeRequest: false,
triggerOnClosedMergeRequest: false,
triggerOnAcceptedMergeRequest: true,
triggerOnNoteRequest: false,
setBuildDescription: true,
branchFilterType: 'All',
secretToken: "14edd1f2fc244d9f6dfc41f093db270a"
)
}
stages {
stage('Build') {
steps {
sh '''
rm -rf postgresql || true
tar -zxvf /home/jenkins/Postgres/postgresql.tar.gz > /dev/null
rm -rf postgresql-13beta2 || true
tar -zxvf /home/jenkins/Postgres/postgresql-13beta2.tar.gz > /dev/null
cd postgresql-13beta2
./configure --prefix=$(pwd)/install > /dev/null
make clean && make > /dev/null
'''
dir("postgresql/contrib") {
dir("postgresql-13beta2/contrib") {
sh 'rm -rf sqlite_fdw || true'
retrySh('git clone ' + SQLITE_FDW_URL)
retrySh('git clone -b ' + env.GIT_BRANCH + ' ' + env.GIT_URL)
}
}
post {
failure {
echo '** BUILD FAILED !!! NEXT STAGE WILL BE SKIPPED **'
emailext subject: "${MAIL_SUBJECT}", body: BUILD_INFO + "\nGit commit: " + env.GIT_URL.replace(".git", "/commit/") + env.GIT_COMMIT + "\n" + '${BUILD_LOG, maxLines=200, escapeHtml=false}', to: "${MAIL_TO}", attachLog: false
updateGitlabCommitStatus name: 'Build', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'Build', state: 'success'
}
}
}
stage('sqlite_fdw_test') {
steps {
dir("postgresql/contrib/sqlite_fdw") {
dir("postgresql-13beta2/contrib/sqlite_fdw") {
catchError() {
sh '''
chmod +x *.sh
./test.sh
'''
}
script {
status = sh(returnStatus: true, script: "grep -q 'All [0-9]* tests passed' 'make_check.out'")
if (status != 0) {
unstable(message: "Set UNSTABLE result")
emailext subject: "${MAIL_SUBJECT}", body: BUILD_INFO + "\nGit commit: " + env.GIT_URL.replace(".git", "/commit/") + env.GIT_COMMIT + "\n" + '${FILE,path="make_check.out"}', to: "${MAIL_TO}", attachLog: false
sh 'cat regression.diffs || true'
updateGitlabCommitStatus name: 'sqlite_fdw_test', state: 'failed'
} else {
updateGitlabCommitStatus name: 'sqlite_fdw_test', state: 'success'
}
}
}
}
}
stage('sqlite_fdw_test_extra') {
steps {
dir("postgresql-13beta2/contrib/sqlite_fdw") {
catchError() {
sh '''
chmod +x ./*.sh || true
rm -rf make_check.out || true
chmod +x *.sh
./test_extra.sh
'''
}
Expand All @@ -69,6 +109,9 @@ pipeline {
unstable(message: "Set UNSTABLE result")
emailext subject: "${MAIL_SUBJECT}", body: BUILD_INFO + "\nGit commit: " + env.GIT_URL.replace(".git", "/commit/") + env.GIT_COMMIT + "\n" + '${FILE,path="make_check.out"}', to: "${MAIL_TO}", attachLog: false
sh 'cat regression.diffs || true'
updateGitlabCommitStatus name: 'sqlite_fdw_test_extra', state: 'failed'
} else {
updateGitlabCommitStatus name: 'sqlite_fdw_test_extra', state: 'success'
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OBJS = connection.o option.o deparse.o sqlite_query.o sqlite_fdw.o
EXTENSION = sqlite_fdw
DATA = sqlite_fdw--1.0.sql

REGRESS = sqlite_fdw type aggregate
REGRESS = extra/sqlite_fdw_post extra/float4 extra/float8 extra/int4 extra/int8 extra/numeric extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/timestamp sqlite_fdw type aggregate

SQLITE_LIB = sqlite3

Expand All @@ -36,8 +36,8 @@ include $(PGXS)
ifndef MAJORVERSION
MAJORVERSION := $(basename $(VERSION))
endif
ifeq (,$(findstring $(MAJORVERSION),9.6 10 11 12))
$(error PostgreSQL 9.6, 10, 11 or 12 is required to compile this extension)
ifeq (,$(findstring $(MAJORVERSION),9.6 10 11 12 13))
$(error PostgreSQL 9.6, 10, 11, 12 or 13 is required to compile this extension)
endif

else
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SQLite Foreign Data Wrapper for PostgreSQL
This PostgreSQL extension is a Foreign Data Wrapper for [SQLite][1].

The current version can work with PostgreSQL 9.6, 10, 11 and 12.
The current version can work with PostgreSQL 9.6, 10, 11, 12 and 13.

## Installation
### 1. Install SQLite library
Expand Down Expand Up @@ -81,7 +81,7 @@ SELECT * FROM t1;
Opening issues and pull requests on GitHub are welcome.

## License
Copyright (c) 2017 - 2019, TOSHIBA Corporation
Copyright (c) 2017 - 2020, TOSHIBA Corporation
Copyright (c) 2011 - 2016, EnterpriseDB 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.
Expand Down
11 changes: 5 additions & 6 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,10 @@ static void
deparseFromExpr(List *quals, deparse_expr_cxt *context)
{
StringInfo buf = context->buf;
RelOptInfo *foreignrel = context->foreignrel;
RelOptInfo *scanrel = context->scanrel;

/* For upper relations, scanrel must be either a joinrel or a baserel */
Assert(foreignrel->reloptkind != RELOPT_UPPER_REL ||
Assert(context->foreignrel->reloptkind != RELOPT_UPPER_REL ||
scanrel->reloptkind == RELOPT_JOINREL ||
scanrel->reloptkind == RELOPT_BASEREL);

Expand Down Expand Up @@ -1770,20 +1769,20 @@ sqlite_deparse_const(Const *node, deparse_expr_cxt *context, int showtype)
appendStringInfoString(buf, extval);
}
else
appendStringInfo(buf, "'%s'", extval);
appendStringInfo(buf, "\'%s\'", extval);
}
break;
case BITOID:
case VARBITOID:
extval = OidOutputFunctionCall(typoutput, node->constvalue);
appendStringInfo(buf, "B'%s'", extval);
appendStringInfo(buf, "B\'%s\'", extval);
break;
case BOOLOID:
extval = OidOutputFunctionCall(typoutput, node->constvalue);
if (strcmp(extval, "t") == 0)
appendStringInfoString(buf, "true");
appendStringInfoString(buf, "1");
else
appendStringInfoString(buf, "false");
appendStringInfoString(buf, "0");
break;

case BYTEAOID:
Expand Down
22 changes: 22 additions & 0 deletions expected/aggregate.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
OPTIONS (database '/tmp/sqlitefdw_test.db');
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
-- test for aggregate pushdown
--Testcase 8:
DROP SERVER IF EXISTS sqlite_svr CASCADE;
NOTICE: drop cascades to foreign table multiprimary
--Testcase 9:
DROP EXTENSION IF EXISTS sqlite_fdw CASCADE;
--Testcase 10:
CREATE EXTENSION sqlite_fdw;
--Testcase 11:
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
OPTIONS (database '/tmp/sqlitefdw_test.db');
--Testcase 12:
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
--Testcase 1:
explain (costs off, verbose) select count(distinct a) from multiprimary;
QUERY PLAN
---------------------------------------------------------------------
Expand All @@ -13,6 +26,7 @@ explain (costs off, verbose) select count(distinct a) from multiprimary;
SQLite query: SELECT count(DISTINCT `a`) FROM main."multiprimary"
(3 rows)

--Testcase 2:
explain (costs off, verbose) select sum(b),max(b), min(b), avg(b) from multiprimary;
QUERY PLAN
----------------------------------------------------------------------------------------
Expand All @@ -21,6 +35,7 @@ explain (costs off, verbose) select sum(b),max(b), min(b), avg(b) from multiprim
SQLite query: SELECT sum(`b`), max(`b`), min(`b`), avg(`b`) FROM main."multiprimary"
(3 rows)

--Testcase 3:
explain (costs off, verbose) select sum(b+5)+2 from multiprimary group by b/2 order by b/2;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -29,6 +44,7 @@ explain (costs off, verbose) select sum(b+5)+2 from multiprimary group by b/2 or
SQLite query: SELECT (sum((`b` + 5)) + 2), (`b` / 2) FROM main."multiprimary" GROUP BY 2 ORDER BY (`b` / 2) ASC NULLS LAST
(3 rows)

--Testcase 4:
explain (costs off, verbose) select sum(a) from multiprimary group by b having sum(a) > 0;
QUERY PLAN
--------------------------------------------------------------------------------------------------
Expand All @@ -37,6 +53,7 @@ explain (costs off, verbose) select sum(a) from multiprimary group by b having s
SQLite query: SELECT sum(`a`), `b` FROM main."multiprimary" GROUP BY 2 HAVING ((sum(`a`) > 0))
(3 rows)

--Testcase 5:
explain (costs off, verbose) select sum(a) from multiprimary group by b having avg(a^2) > 0 and sum(a) > 0;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -50,6 +67,7 @@ explain (costs off, verbose) select sum(a) from multiprimary group by b having a
(7 rows)

-- stddev and variance are not pushed down
--Testcase 6:
explain (costs off, verbose) select stddev(a) from multiprimary;
QUERY PLAN
-----------------------------------------------------------
Expand All @@ -60,6 +78,7 @@ explain (costs off, verbose) select stddev(a) from multiprimary;
SQLite query: SELECT `a` FROM main."multiprimary"
(5 rows)

--Testcase 7:
explain (costs off, verbose) select sum(a) from multiprimary group by b having variance(a) > 0;
QUERY PLAN
--------------------------------------------------------------------------------------------
Expand All @@ -72,6 +91,9 @@ explain (costs off, verbose) select sum(a) from multiprimary group by b having v
SQLite query: SELECT `a`, `b` FROM main."multiprimary" ORDER BY `b` ASC NULLS LAST
(7 rows)

--Testcase 13:
DROP FOREIGN TABLE multiprimary;
--Testcase 14:
DROP SERVER sqlite_svr;
--Testcase 15:
DROP EXTENSION sqlite_fdw CASCADE;
Loading

0 comments on commit 1f64853

Please sign in to comment.