Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sql logic test #5578

Merged
merged 8 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/test_sqllogic_standalone/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
- name: Install python dependences
shell: bash
run: |
pip3 install --user boto3 "moto[all]" yapf shfmt-py mysql-connector pymysql six PyHamcrest requests
pip3 install --user boto3 "moto[all]" yapf shfmt-py mysql-connector pymysql six PyHamcrest requests environs

- name: Run sqllogic Tests with Standalone mode, with embedded meta-store
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion tests/logictest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From python:3.10.4-alpine3.15

RUN /usr/local/bin/python -m pip install --upgrade pip && pip install --user mysql-connector six PyHamcrest requests
RUN /usr/local/bin/python -m pip install --upgrade pip && pip install --user mysql-connector six PyHamcrest requests environs
COPY *.py /
COPY suites/* /suites/
WORKDIR /
Expand Down
28 changes: 25 additions & 3 deletions tests/logictest/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

# Targets

The database return right with diffrent handlers, for example mysql and http
The database return right with different handlers, for example mysql and http

# Usage

## prepare
1. Change to the scripts dir, cd tests/logictest/
2. Make sure python3 is installed
3. Using [Poetry](https://github.com/python-poetry/poetry) to install dependency, dependency see tests/pyproject.toml
4. (Optional)If use pip, you can find dependency in Dockerfile

## Need to Known
## Need to known
1. Cases from **tests/suites/0_stateless/** to **tests/logictest/suites/gen/**
2. If a case file already exists in gen/, gen_suites will ignore it.
3. Regenerate:delete case file in gen/ and run gen_suites.py
Expand All @@ -21,6 +22,27 @@ The database return right with diffrent handlers, for example mysql and http
## Run logic test
1. python3 main.py

## Docker

### Build image

docker build -t sqllogic/test:latest .

### Run with docker

1. Image release: public.ecr.aws/k3y0u5f2/sqllogic/test:latest
2. Set envs
- DISABLE_MYSQL_LOGIC_TEST (if anything set, will skip mysql handler)
- DISABLE_HTTP_LOGIC_TEST (if anything set, will skip http handler)
- QUERY_MYSQL_HANDLER_HOST
- QUERY_MYSQL_HANDLER_PORT
- QUERY_HTTP_HANDLER_HOST
- QUERY_HTTP_HANDLER_PORT
- MYSQL_DATABASE
- MYSQL_USER
- ADDITIONAL_HEADERS (for security scenario)
3. docker run --name logictest --rm --network host public.ecr.aws/k3y0u5f2/sqllogic/test:latest

# Learn More

See pr: https://github.com/datafuselabs/databend/pull/5048
Ref pr: https://github.com/datafuselabs/databend/pull/5048
5 changes: 4 additions & 1 deletion tests/logictest/http_connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

import environs
import requests
Expand Down Expand Up @@ -97,8 +98,10 @@ def connect(self, host, port, user="root", database=default_database):
self._database = database
self._session_max_idle_time = 300
self._session = None
self._additonal_headers = dict()
e = environs.Env()
self._additonal_headers = e.dict("ADDITIONAL_HEADERS")
if os.getenv("ADDITIONAL_HEADERS") is not None:
self._additonal_headers = e.dict("ADDITIONAL_HEADERS")

def query(self, statement, session=None):
url = "http://{}:{}/v1/query/".format(self._host, self._port)
Expand Down
6 changes: 5 additions & 1 deletion tests/logictest/logictest.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ def assert_query_equal(self, f, resultset, statement):

def assert_execute_query(self, statement):
actual = safe_execute(lambda: self.execute_query(statement), statement)
f = format_value(actual, len(statement.s_type.query_type))
try:
f = format_value(actual, len(statement.s_type.query_type))
except Exception:
log.warning("{} statement type is query but return nothing".format(statement))
raise
assert statement.results is not None and len(
statement.results) > 0, "No result found {}".format(statement)
hasResult = False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
statement ok
CREATE TABLE IF NOT EXISTS objects_test1(id TINYINT, obj OBJECT, var VARIANT) Engine=Memory;

statement ok
insert into objects_test1 values (1, parse_json('{"a": 1, "b": [1,2,3]}'), parse_json('{"1": 2}'));

-- TODO: Bug here, http handler return state running
-- statement ok
-- select id, object_keys(obj), object_keys(var) from objects_test1;

statement ok
drop table objects_test1;

statement error 1010
select object_keys(parse_json('[1,2,3]'));

statement error 1010
select object_keys(1);

Loading