Skip to content
Snippets Groups Projects
Unverified Commit 52f5a0e7 authored by Yee's avatar Yee Committed by GitHub
Browse files

Move starts/ends with and label expression tests to TCK framework (#577)


Co-authored-by: default avatarjie.wang <38901892+jievince@users.noreply.github.com>
parent 8b5e38d2
No related branches found
No related tags found
No related merge requests found
# --coding:utf-8--
#
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
import time
import re
from tests.common.nebula_test_suite import NebulaTestSuite
class TestLabelExpr(NebulaTestSuite):
@classmethod
def prepare(self):
resp = self.execute('CREATE SPACE test_label_expr(partition_num=1);'
'USE test_label_expr;')
self.check_resp_succeeded(resp)
resp = self.execute('CREATE TAG person(name string, age int); '
'CREATE EDGE friend(start int)')
self.check_resp_succeeded(resp)
time.sleep(self.delay)
resp = self.execute('INSERT VERTEX person(name, age) values "a":("a", 2), "b":("b", 3);')
self.check_resp_succeeded(resp)
resp = self.execute('INSERT EDGE friend(start) values "a"->"b":(2010);')
self.check_resp_succeeded(resp)
@classmethod
def cleanup(self):
resp = self.execute('DROP SPACE test_label_expr')
self.check_resp_succeeded(resp)
def test_wrong_props(self):
# fetch vertex with label expr
resp = self.execute('FETCH PROP ON person "a" YIELD name')
self.check_error_msg(resp, "SemanticError: Invalid label identifiers: name")
resp = self.execute('FETCH PROP ON person "a" YIELD name + 1')
self.check_error_msg(resp, "SemanticError: Invalid label identifiers: name")
# fetch edge with label expr
resp = self.execute('FETCH PROP ON friend "a"->"b" YIELD start')
self.check_error_msg(resp, "SemanticError: Invalid label identifiers: start")
# go with label expr
resp = self.execute('GO FROM "a" OVER friend YIELD name')
self.check_error_msg(resp, "SemanticError: Invalid label identifiers: name")
# yield sentence with label expr
resp = self.execute('YIELD name')
self.check_error_msg(resp, "SemanticError: Invalid label identifiers: name")
# --coding:utf-8--
#
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
import pytest
from tests.common.nebula_test_suite import NebulaTestSuite
from tests.common.nebula_test_suite import T_NULL_BAD_TYPE
class TestStartsWithAndEndsWith(NebulaTestSuite):
@classmethod
def prepare(self):
self.use_nba()
def test_starts_with(self):
stmt = "YIELD 'apple' STARTS WITH 'app'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['(apple STARTS WITH app)'],
"rows": [
[True]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' STARTS WITH 'a'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['(apple STARTS WITH a)'],
"rows": [
[True]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' STARTS WITH 'A'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['(apple STARTS WITH A)'],
"rows": [
[False]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' STARTS WITH 'b'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['(apple STARTS WITH b)'],
"rows": [
[False]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD '123' STARTS WITH '1'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
# expected column names should contain "" or '' if the query contains a string
# to fix this issue, update toString() method in modules/common/src/common/datatypes/Value.cpp
# the fix could causes past tests fail
expected_data = {
"column_names": ['(123 STARTS WITH 1)'],
"rows": [
[True]
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 123 STARTS WITH 1"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['(123 STARTS WITH 1)'],
"rows": [
[T_NULL_BAD_TYPE]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
def test_not_starts_with(self):
stmt = "YIELD 'apple' NOT STARTS WITH 'app'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT STARTS WITH 'a'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT STARTS WITH 'A'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT STARTS WITH 'b'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD '123' NOT STARTS WITH '1'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 123 NOT STARTS WITH 1"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[T_NULL_BAD_TYPE]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
def test_starts_with_GO(self):
stmt = '''GO FROM 'Tony Parker' OVER like WHERE like._dst STARTS WITH 'LaMarcus' YIELD $^.player.name'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name'],
"rows": [
['Tony Parker']
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''GO FROM 'Tony Parker' OVER like WHERE like._dst STARTS WITH 'Obama' YIELD $^.player.name'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name'],
"rows": [
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
def test_not_starts_with_GO(self):
stmt = '''GO FROM 'Tony Parker' OVER like WHERE like._dst NOT STARTS WITH 'T' YIELD $^.player.name'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name'],
"rows": [
['Tony Parker'],
['Tony Parker'],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''$A = GO FROM 'Tony Parker' OVER like YIELD like._dst AS ID;
GO FROM $A.ID OVER like WHERE like.likeness NOT IN [95,56,21]
AND $$.player.name NOT STARTS WITH 'Tony' YIELD $^.player.name, $$.player.name, like.likeness'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name', '$$.player.name', 'like.likeness'],
"rows": [
['Manu Ginobili', 'Tim Duncan', 90],
['LaMarcus Aldridge', 'Tim Duncan', 75],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''$A = GO FROM 'Tony Parker' OVER like YIELD like._dst AS ID;
GO FROM $A.ID OVER like WHERE like.likeness NOT IN [95,56,21]
AND $^.player.name NOT STARTS WITH 'LaMarcus' YIELD $^.player.name, $$.player.name, like.likeness'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name', '$$.player.name', 'like.likeness'],
"rows": [
['Manu Ginobili', 'Tim Duncan', 90],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = '''$A = GO FROM 'Tony Parker' OVER like YIELD like._dst AS ID;
GO FROM $A.ID OVER like WHERE like.likeness NOT IN [95,56,21]
AND $$.player.name NOT STARTS WITH 'Tony' YIELD $^.player.name, $$.player.name, like.likeness'''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name', '$$.player.name', 'like.likeness'],
"rows": [
['Manu Ginobili', 'Tim Duncan', 90],
['LaMarcus Aldridge', 'Tim Duncan', 75],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
def test_ends_with(self):
stmt = "YIELD 'apple' ENDS WITH 'le'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' ENDS WITH 'app'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' ENDS WITH 'a'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' ENDS WITH 'e'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' ENDS WITH 'E'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' ENDS WITH 'b'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD '123' ENDS WITH '3'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 123 ENDS WITH 3"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[T_NULL_BAD_TYPE]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
def test_not_ends_with(self):
stmt = "YIELD 'apple' NOT ENDS WITH 'le'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT ENDS WITH 'app'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT ENDS WITH 'a'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT ENDS WITH 'e'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT ENDS WITH 'E'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 'apple' NOT ENDS WITH 'b'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[True]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD '123' NOT ENDS WITH '3'"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[False]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
stmt = "YIELD 123 NOT ENDS WITH 3"
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": [],
"rows": [
[T_NULL_BAD_TYPE]
]
}
self.check_out_of_order_result(resp, expected_data["rows"])
def test_ends_with_GO(self):
stmt = '''GO FROM 'Tony Parker' OVER like WHERE like._dst ENDS WITH 'Ginobili' YIELD $^.player.name '''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
# print(resp)
expected_data = {
"column_names": ['$^.player.name'],
"rows": [
['Tony Parker'],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
def test_not_ends_with_GO(self):
stmt = '''GO FROM 'Tony Parker' OVER like WHERE like._dst NOT ENDS WITH 'Ginobili' YIELD $^.player.name '''
resp = self.execute(stmt)
self.check_resp_succeeded(resp)
expected_data = {
"column_names": ['$^.player.name'],
"rows": [
['Tony Parker'],
['Tony Parker'],
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Ends With Expression
Background:
Given a graph with space named "nba"
Scenario: yield ends with
When executing query:
"""
YIELD 'apple' ENDS WITH 'le'
"""
Then the result should be, in any order:
| (apple ENDS WITH le) |
| true |
When executing query:
"""
YIELD 'apple' ENDS WITH 'app'
"""
Then the result should be, in any order:
| (apple ENDS WITH app) |
| false |
When executing query:
"""
YIELD 'apple' ENDS WITH 'a'
"""
Then the result should be, in any order:
| (apple ENDS WITH a) |
| false |
When executing query:
"""
YIELD 'apple' ENDS WITH 'e'
"""
Then the result should be, in any order:
| (apple ENDS WITH e) |
| true |
When executing query:
"""
YIELD 'apple' ENDS WITH 'E'
"""
Then the result should be, in any order:
| (apple ENDS WITH E) |
| false |
When executing query:
"""
YIELD 'apple' ENDS WITH 'b'
"""
Then the result should be, in any order:
| (apple ENDS WITH b) |
| false |
When executing query:
"""
YIELD '123' ENDS WITH '3'
"""
Then the result should be, in any order:
| (123 ENDS WITH 3) |
| true |
When executing query:
"""
YIELD 123 ENDS WITH 3
"""
Then the result should be, in any order:
| (123 ENDS WITH 3) |
| BAD_TYPE |
Scenario: yield not ends with
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'le'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH le) |
| false |
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'app'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH app) |
| true |
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'a'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH a) |
| true |
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'e'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH e) |
| false |
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'E'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH E) |
| true |
When executing query:
"""
YIELD 'apple' NOT ENDS WITH 'b'
"""
Then the result should be, in any order:
| (apple NOT ENDS WITH b) |
| true |
When executing query:
"""
YIELD '123' NOT ENDS WITH '3'
"""
Then the result should be, in any order:
| (123 NOT ENDS WITH 3) |
| false |
When executing query:
"""
YIELD 123 NOT ENDS WITH 3
"""
Then the result should be, in any order:
| (123 NOT ENDS WITH 3) |
| BAD_TYPE |
Scenario: ends with go
When executing query:
"""
GO FROM 'Tony Parker' OVER like
WHERE like._dst ENDS WITH 'Ginobili'
YIELD $^.player.name
"""
Then the result should be, in any order:
| $^.player.name |
| 'Tony Parker' |
Scenario: not ends with go
When executing query:
"""
GO FROM 'Tony Parker' OVER like
WHERE like._dst NOT ENDS WITH 'Ginobili'
YIELD $^.player.name
"""
Then the result should be, in any order:
| $^.player.name |
| 'Tony Parker' |
| 'Tony Parker' |
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Label Expression
Examples:
| space_name | vid | vid2 |
| nba | "Tim Duncan" | "Tony Parker" |
| nba_int_vid | hash("Tim Duncan") | hash("Tony Parker") |
Scenario Outline: raise invalid label semantic errors
Given a graph with space named "<space_name>"
When executing query:
"""
FETCH PROP ON player <vid> YIELD name
"""
Then a SemanticError should be raised at runtime: Invalid label identifiers: name
When executing query:
"""
FETCH PROP ON player <vid> YIELD name + 1
"""
Then a SemanticError should be raised at runtime: Invalid label identifiers: name
When executing query:
"""
FETCH PROP ON like <vid>-><vid2> YIELD likeness
"""
Then a SemanticError should be raised at runtime: Invalid label identifiers: likeness
When executing query:
"""
GO FROM <vid> OVER like YIELD name
"""
Then a SemanticError should be raised at runtime: Invalid label identifiers: name
When executing query:
"""
YIELD name
"""
Then a SemanticError should be raised at runtime: Invalid label identifiers: name
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Starts With Expression
Background:
Given a graph with space named "nba"
Scenario: yield starts with
When executing query:
"""
YIELD 'apple' STARTS WITH 'app'
"""
Then the result should be, in any order:
| (apple STARTS WITH app) |
| true |
When executing query:
"""
YIELD 'apple' STARTS WITH 'a'
"""
Then the result should be, in any order:
| (apple STARTS WITH a) |
| true |
When executing query:
"""
YIELD 'apple' STARTS WITH 'A'
"""
Then the result should be, in any order:
| (apple STARTS WITH A) |
| false |
When executing query:
"""
YIELD 'apple' STARTS WITH 'b'
"""
Then the result should be, in any order:
| (apple STARTS WITH b) |
| false |
When executing query:
"""
YIELD '123' STARTS WITH '1'
"""
Then the result should be, in any order:
| (123 STARTS WITH 1) |
| true |
When executing query:
"""
YIELD 123 STARTS WITH 1
"""
Then the result should be, in any order:
| (123 STARTS WITH 1) |
| BAD_TYPE |
Scenario: yield not starts with
When executing query:
"""
YIELD 'apple' NOT STARTS WITH 'app'
"""
Then the result should be, in any order:
| (apple NOT STARTS WITH app) |
| false |
When executing query:
"""
YIELD 'apple' NOT STARTS WITH 'a'
"""
Then the result should be, in any order:
| (apple NOT STARTS WITH a) |
| false |
When executing query:
"""
YIELD 'apple' NOT STARTS WITH 'A'
"""
Then the result should be, in any order:
| (apple NOT STARTS WITH A) |
| true |
When executing query:
"""
YIELD 'apple' NOT STARTS WITH 'b'
"""
Then the result should be, in any order:
| (apple NOT STARTS WITH b) |
| true |
When executing query:
"""
YIELD '123' NOT STARTS WITH '1'
"""
Then the result should be, in any order:
| (123 NOT STARTS WITH 1) |
| false |
When executing query:
"""
YIELD 123 NOT STARTS WITH 1
"""
Then the result should be, in any order:
| (123 NOT STARTS WITH 1) |
| BAD_TYPE |
Scenario: starts with go
When executing query:
"""
GO FROM 'Tony Parker' OVER like
WHERE like._dst STARTS WITH 'LaMarcus'
YIELD $^.player.name
"""
Then the result should be, in any order:
| $^.player.name |
| 'Tony Parker' |
When executing query:
"""
GO FROM 'Tony Parker' OVER like
WHERE like._dst STARTS WITH 'Obama'
YIELD $^.player.name
"""
Then the result should be, in any order:
| $^.player.name |
Scenario: not starts with go
When executing query:
"""
GO FROM 'Tony Parker' OVER like
WHERE like._dst NOT STARTS WITH 'T'
YIELD $^.player.name
"""
Then the result should be, in any order:
| $^.player.name |
| 'Tony Parker' |
| 'Tony Parker' |
When executing query:
"""
$A = GO FROM 'Tony Parker' OVER like YIELD like._dst AS ID;
GO FROM $A.ID OVER like
WHERE like.likeness NOT IN [95,56,21] AND $$.player.name NOT STARTS WITH 'Tony'
YIELD $^.player.name, $$.player.name, like.likeness
"""
Then the result should be, in any order:
| $^.player.name | $$.player.name | like.likeness |
| 'Manu Ginobili' | 'Tim Duncan' | 90 |
| 'LaMarcus Aldridge' | 'Tim Duncan' | 75 |
When executing query:
"""
$A = GO FROM 'Tony Parker' OVER like YIELD like._dst AS ID;
GO FROM $A.ID OVER like
WHERE like.likeness NOT IN [95,56,21] AND $^.player.name NOT STARTS WITH 'LaMarcus'
YIELD $^.player.name, $$.player.name, like.likeness
"""
Then the result should be, in any order:
| $^.player.name | $$.player.name | like.likeness |
| 'Manu Ginobili' | 'Tim Duncan' | 90 |
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment