Skip to content

Commit

Permalink
fix table reference
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed May 18, 2023
1 parent 208628f commit 971d99d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ build-ceresdb:
build-test:
cargo build

build: build-ceresdb build-test build-meta
build: build-ceresdb build-test

kill-old-process:
killall ceresdb-server | true
killall ceresmeta | true

prepare: clean build kill-old-process

run: prepare
run: prepare build-meta
$(CERESDB_TEST_BINARY)

run-local: prepare
CERESDB_ENV_FILTER=local $(CERESDB_TEST_BINARY)

run-cluster: prepare
run-cluster: prepare build-meta
CERESDB_ENV_FILTER=cluster $(CERESDB_TEST_BINARY)

run-java:
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/build_meta.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -exo
set -e

SRC=/tmp/ceresmeta-src
TARGET=$(pwd)/ceresmeta
Expand Down
20 changes: 18 additions & 2 deletions integration_tests/prom/remote-query.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def now():
return int(time.time()) * 1000

table = 'prom_remote_query_test' + str(now())
table2 = 'PROM_REMOTE_QUERY_TEST' + str(now())

def execute_sql(sql):
r = requests.post('{}/sql'.format(api_root), json={'query': sql}, headers=headers)
Expand All @@ -25,7 +26,8 @@ def execute_pql(pql):
return r.json()

def prepare_data(ts):
execute_sql("""
for t in [table, table2]:
execute_sql("""
CREATE TABLE if not exists `{}` (
`t` timestamp NOT NULL,
`tag1` string TAG,
Expand All @@ -34,7 +36,7 @@ def prepare_data(ts):
`VALUE2` double NOT NULL,
timestamp KEY (t)
);
""".format(table))
""".format(table))

execute_sql("""
insert into {}(t, tag1, tag2, value, VALUE2)
Expand All @@ -44,6 +46,14 @@ def prepare_data(ts):
;
""".format(table, ts-5000, ts))

execute_sql("""
insert into {}(t, tag1, tag2, value, VALUE2)
values
({}, "v1", "v2", 10, 20),
({}, "v1", "v2", 110, 220)
;
""".format(table2, ts-5000, ts))


def remote_query(ts):
ts = ts/1000 # prom return seconds
Expand All @@ -64,10 +74,16 @@ def remote_query(ts):
result = r['data']['result']
assert result == []

# uppercase field
r = execute_pql(table + '{tag1="v1",__ceresdb_field__="VALUE2"}[5m]')
result = r['data']['result']
assert result == [{'metric': {'__name__': table, 'tag1': 'v1', 'tag2': 'v2'}, 'values': [[ts-5, '2'], [ts, '22']]}]

# uppercase table
r = execute_pql(table2 + '{tag1="v1"}[5m]')
result = r['data']['result']
assert result == [{'metric': {'__name__': table2, 'tag1': 'v1', 'tag2': 'v2'}, 'values': [[ts-5, '1'], [ts, '11']]}]

def main():
ts = now()
prepare_data(ts)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/prom/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

VERSION=prometheus-2.43.0.linux-amd64
wget "https://github.com/prometheus/prometheus/releases/download/v2.43.0/${VERSION}.tar.gz"
wget -q "https://github.com/prometheus/prometheus/releases/download/v2.43.0/${VERSION}.tar.gz"

tar xvf prometheus*.tar.gz
nohup ./${VERSION}/prometheus --config.file ./prometheus.yml &
Expand Down
9 changes: 1 addition & 8 deletions query_frontend/src/promql/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,8 @@ pub fn remote_query_to_plan<P: MetaProvider>(
) -> Result<RemoteQueryPlan> {
let (metric, field, mut filters) = normalize_matchers(query.matchers)?;

// get table schema
let table_ref = meta_provider
.table(TableReference::parse_str(&metric))
.context(MetaProviderError {
msg: format!("Failed to find table, name:{metric}"),
})?
.context(TableNotFound { name: &metric })?;
let table_provider = meta_provider
.get_table_provider(table_ref.name().into())
.get_table_provider(TableReference::bare(&metric))
.context(TableProviderNotFound { name: &metric })?;
let schema = Schema::try_from(table_provider.schema()).context(BuildTableSchema)?;
let timestamp_col_name = schema.timestamp_name();
Expand Down

0 comments on commit 971d99d

Please sign in to comment.