Skip to content

Commit

Permalink
[feature](jdbc catalog) support db2 jdbc catalog (apache#31627)
Browse files Browse the repository at this point in the history
  • Loading branch information
zy-kkk authored Mar 1, 2024
1 parent e32c10d commit c73b425
Show file tree
Hide file tree
Showing 25 changed files with 998 additions and 41 deletions.
19 changes: 19 additions & 0 deletions docker/thirdparties/docker-compose/db2/db2.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

DOCKER_DB2_EXTERNAL_PORT=50000
54 changes: 54 additions & 0 deletions docker/thirdparties/docker-compose/db2/db2.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

version: '3'

services:
doris--db2_11:
image: ibmcom/db2:11.5.0.0a
ports:
- ${DOCKER_DB2_EXTERNAL_PORT}:50000
privileged: true
healthcheck:
test: ["CMD-SHELL", "su - db2inst1 -c \"db2 connect to doris && db2 'select 1 from sysibm.sysdummy1'\""]
interval: 20s
timeout: 60s
retries: 10
volumes:
- ./init:/docker-entrypoint-initdb.d
environment:
- LICENSE=accept
- DBNAME=doris
- DB2INSTANCE=db2inst1
- DB2INST1_PASSWORD=123456
- TZ=Asia/Shanghai
restart: always
networks:
- doris--db2_network
db2-hello-world:
image: hello-world
depends_on:
doris--db2_11:
condition: service_healthy
networks:
- doris--db2_network
networks:
doris--db2_network:
ipam:
driver: default
config:
- subnet: 168.50.0.0/24
18 changes: 18 additions & 0 deletions docker/thirdparties/docker-compose/db2/init/01-drop-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

drop schema doris_test restrict;
18 changes: 18 additions & 0 deletions docker/thirdparties/docker-compose/db2/init/02-create-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

create schema doris_test;
40 changes: 40 additions & 0 deletions docker/thirdparties/docker-compose/db2/init/03-create-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

CREATE TABLE doris_test.sample_table (
id_column INT GENERATED ALWAYS AS IDENTITY,
numeric_column NUMERIC,
decimal_column DECIMAL(31, 10),
decfloat_column DECFLOAT,
float_column FLOAT,
real_column REAL,
double_column DOUBLE,
double_precision_column DOUBLE PRECISION,
smallint_column SMALLINT,
int_column INT,
bigint_column BIGINT,
varchar_column VARCHAR(255),
varcharphic_column VARGRAPHIC(50),
long_varchar_column LONG VARCHAR ,
long_varcharphic_column LONG VARGRAPHIC,
char_varying_column CHAR VARYING(255),
char_column CHAR(255),
date_column DATE,
timestamp_column TIMESTAMP,
time_column TIME,
clob_column CLOB
);
150 changes: 150 additions & 0 deletions docker/thirdparties/docker-compose/db2/init/04-insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

-- Insert normal data
INSERT INTO doris_test.sample_table (
numeric_column,
decimal_column,
decfloat_column,
float_column,
real_column,
double_column,
double_precision_column,
smallint_column,
int_column,
bigint_column,
varchar_column,
varcharphic_column,
long_varchar_column,
long_varcharphic_column,
char_varying_column,
char_column,
date_column,
timestamp_column,
time_column,
clob_column
) VALUES (
123,
1234567890.1234567890,
1.234567890,
12345.6789,
12345.6789,
1234567890.1234567890,
1234567890.1234567890,
123,
12345,
123456789012345,
'Varchar text',
'Varcharphic text',
'Long varchar text',
'Long varcharphic text',
'Char varying text',
'Char text',
'2024-01-24',
'2024-01-24-12.34.56.789000',
'12:34:56',
'Sample CLOB text'
);

-- Insert null data
INSERT INTO doris_test.sample_table (
numeric_column,
decimal_column,
decfloat_column,
float_column,
real_column,
double_column,
double_precision_column,
smallint_column,
int_column,
bigint_column,
varchar_column,
varcharphic_column,
long_varchar_column,
long_varcharphic_column,
char_varying_column,
char_column,
date_column,
timestamp_column,
time_column,
clob_column
) VALUES (
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
);

INSERT INTO doris_test.sample_table (
numeric_column,
decimal_column,
decfloat_column,
float_column,
real_column,
double_column,
double_precision_column,
smallint_column,
int_column,
bigint_column,
varchar_column,
varcharphic_column,
long_varchar_column,
long_varcharphic_column,
char_varying_column,
char_column,
date_column,
timestamp_column,
time_column,
clob_column
) VALUES (
123,
1234567890.1234567890,
1.234567890,
12345.6789,
12345.6789,
1234567890.1234567890,
1234567890.1234567890,
123,
12345,
123456789012345,
'中文一',
'中文二',
'中文三',
'中文四',
'中文五',
'中文六',
'2024-01-24',
'2024-01-24-12.34.56.789000',
'12:34:56',
'中文七'
);
21 changes: 18 additions & 3 deletions docker/thirdparties/run-thirdparties-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Usage: $0 <options>
--stop stop the specified components
All valid components:
mysql,pg,oracle,sqlserver,clickhouse,es,hive,iceberg,hudi,trino,kafka,mariadb
mysql,pg,oracle,sqlserver,clickhouse,es,hive,iceberg,hudi,trino,kafka,mariadb,db2
"
exit 1
}
Expand All @@ -60,7 +60,7 @@ STOP=0

if [[ "$#" == 1 ]]; then
# default
COMPONENTS="mysql,es,hive,pg,oracle,sqlserver,clickhouse,mariadb,iceberg"
COMPONENTS="mysql,es,hive,pg,oracle,sqlserver,clickhouse,mariadb,iceberg,db2"
else
while true; do
case "$1" in
Expand Down Expand Up @@ -92,7 +92,7 @@ else
done
if [[ "${COMPONENTS}"x == ""x ]]; then
if [[ "${STOP}" -eq 1 ]]; then
COMPONENTS="mysql,es,pg,oracle,sqlserver,clickhouse,hive,iceberg,hudi,trino,kafka,mariadb"
COMPONENTS="mysql,es,pg,oracle,sqlserver,clickhouse,hive,iceberg,hudi,trino,kafka,mariadb,db2"
fi
fi
fi
Expand Down Expand Up @@ -133,6 +133,7 @@ RUN_TRINO=0
RUN_KAFKA=0
RUN_SPARK=0
RUN_MARIADB=0
RUN_DB2=0

for element in "${COMPONENTS_ARR[@]}"; do
if [[ "${element}"x == "mysql"x ]]; then
Expand Down Expand Up @@ -161,6 +162,8 @@ for element in "${COMPONENTS_ARR[@]}"; do
RUN_SPARK=1
elif [[ "${element}"x == "mariadb"x ]];then
RUN_MARIADB=1
elif [[ "${element}"x == "db2"x ]];then
RUN_DB2=1
else
echo "Invalid component: ${element}"
usage
Expand Down Expand Up @@ -228,6 +231,18 @@ if [[ "${RUN_ORACLE}" -eq 1 ]]; then
fi
fi

if [[ "${RUN_DB2}" -eq 1 ]]; then
# db2
cp "${ROOT}"/docker-compose/db2/db2.yaml.tpl "${ROOT}"/docker-compose/db2/db2.yaml
sed -i "s/doris--/${CONTAINER_UID}/g" "${ROOT}"/docker-compose/db2/db2.yaml
sudo docker compose -f "${ROOT}"/docker-compose/db2/db2.yaml --env-file "${ROOT}"/docker-compose/db2/db2.env down
if [[ "${STOP}" -ne 1 ]]; then
sudo rm "${ROOT}"/docker-compose/db2/data/* -rf
sudo mkdir -p "${ROOT}"/docker-compose/db2/data/
sudo docker compose -f "${ROOT}"/docker-compose/db2/db2.yaml --env-file "${ROOT}"/docker-compose/db2/db2.env up -d
fi
fi

if [[ "${RUN_SQLSERVER}" -eq 1 ]]; then
# sqlserver
cp "${ROOT}"/docker-compose/sqlserver/sqlserver.yaml.tpl "${ROOT}"/docker-compose/sqlserver/sqlserver.yaml
Expand Down
Loading

0 comments on commit c73b425

Please sign in to comment.