code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
async def test_edgeql_ddl_ptr_set_required_01(self):
await self.con.execute(r"""
CREATE TYPE Bar {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT std::exclusive;
}
};
CREATE TYPE Foo {
CREATE PROPERTY p -> str;
CREATE PROPERTY p2 -> str;
CREATE MULTI PROPERTY m_p -> str;
CREATE LINK l -> Bar {
CREATE PROPERTY lp -> str;
};
CREATE MULTI LINK m_l -> Bar {
CREATE PROPERTY lp -> str;
};
};
INSERT Bar {name := 'bar1'};
INSERT Bar {name := 'bar2'};
WITH
bar := (SELECT Bar FILTER .name = 'bar1' LIMIT 1),
bars := (SELECT Bar),
INSERT Foo {
p := '1',
p2 := '1',
m_p := {'1', '2'},
l := bar { @lp := '1' },
m_l := (
FOR bar IN {enumerate(bars)}
UNION (SELECT bar.1 { @lp := <str>(bar.0 + 1) })
),
};
INSERT Foo {
p2 := '3',
};
""")
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET REQUIRED USING ('3')
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': '1'},
{'p': '3'},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET REQUIRED USING ('3')
}
""")
await self.assert_query_result(
'SELECT Foo { m_p } ORDER BY .p',
[
{'m_p': {'1', '2'}},
{'m_p': {'3'}},
],
)
# Something simple but forcing it to use assert_exists
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET REQUIRED USING (
assert_exists((select '3' filter true)))
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': '1'},
{'p': '3'},
],
)
# A reference to another property of the same host type.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET REQUIRED USING (.p2)
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': '1'},
{'p': '3'},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET REQUIRED USING (.p2)
}
""")
await self.assert_query_result(
'SELECT Foo { m_p } ORDER BY .p',
[
{'m_p': {'1', '2'}},
{'m_p': {'3'}},
],
)
# ... should fail if empty set is produced by the USING clause
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required property 'p'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET REQUIRED USING (<str>{})
}
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required property 'm_p'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET REQUIRED USING (
<str>{} IF True ELSE .p2
)
}
""")
# And now see about the links.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l {
SET REQUIRED USING (SELECT Bar FILTER .name = 'bar2')
}
""")
await self.assert_query_result(
'SELECT Foo { l: {name} } ORDER BY .p EMPTY LAST',
[
{'l': {'name': 'bar1'}},
{'l': {'name': 'bar2'}},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER LINK m_l {
SET REQUIRED USING (SELECT Bar FILTER .name = 'bar2')
}
""")
await self.assert_query_result(
'''
SELECT Foo { m_l: {name} ORDER BY .name }
ORDER BY .p EMPTY LAST
''',
[
{'m_l': [{'name': 'bar1'}, {'name': 'bar2'}]},
{'m_l': [{'name': 'bar2'}]},
],
)
# Check that minimum cardinality constraint is enforced on links too...
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required link 'l'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l {
SET REQUIRED USING (SELECT Bar FILTER false LIMIT 1)
}
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required link 'm_l'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK m_l {
SET REQUIRED USING (SELECT Bar FILTER false LIMIT 1)
}
""") | )
async with self._run_and_rollback():
await self.con.execute( | test_edgeql_ddl_ptr_set_required_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_property_09(self):
await self.con.execute("""
create type T;
create type S {
create multi link x -> T {
create property id -> str;
create index on (__subject__@id);
}
};
insert T;
insert S { x := (select T { @id := "lol" }) };
""")
await self.assert_query_result(
r"""
select S { x: {id, @id} }
""",
[{'x': [{'id': str, '@id': "lol"}]}],
# The python bindings seem to misbehave when there is
# linkprop and a regular prop with the same name
json_only=True,
) | )
await self.assert_query_result(
r | test_edgeql_ddl_link_property_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_property_10(self):
await self.con.execute("""
CREATE TYPE default::User;
CREATE TYPE default::Survey {
CREATE MULTI LINK recipients -> default::User;
};
insert Survey { recipients := (insert User) };
""")
await self.con.execute("""
alter type Survey alter link recipients
create property destination -> str { set default := "email" };
""")
await self.assert_query_result(
r"""
select Survey { recipients: {@destination} };
""",
[{"recipients": [{"@destination": "email"}]}]
) | )
await self.con.execute( | test_edgeql_ddl_link_property_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_long_01(self):
link_name = (
'f123456789_123456789_123456789_123456789'
'_123456789_123456789_123456789_123456789'
)
await self.con.execute(f"""
CREATE ABSTRACT LINK {link_name};
""")
await self.con.execute(f"""
CREATE TYPE Foo {{
CREATE LINK {link_name} -> Foo;
}};
""")
await self.con.query(f"SELECT Foo.{link_name}") | )
await self.con.execute(f | test_edgeql_ddl_link_long_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_property_long_01(self):
prop_name = (
'f123456789_123456789_123456789_123456789'
'_123456789_123456789_123456789_123456789'
)
await self.con.execute(f"""
CREATE ABSTRACT PROPERTY {prop_name}
""")
await self.con.execute(f"""
CREATE TYPE Foo {{
CREATE PROPERTY {prop_name} -> std::str;
}};
""")
await self.con.query(f"SELECT Foo.{prop_name}") | )
await self.con.execute(f | test_edgeql_ddl_property_long_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_01(self):
await self.con.execute("""
CREATE FUNCTION my_lower(s: std::str) -> std::str
USING SQL FUNCTION 'lower';
""")
with self.assertRaisesRegex(edgedb.DuplicateFunctionDefinitionError,
r'cannot create.*my_lower.*func'):
async with self.con.transaction():
await self.con.execute("""
CREATE FUNCTION my_lower(s: SET OF std::str)
-> std::str {
SET initial_value := '';
USING SQL FUNCTION 'count';
};
""")
await self.con.execute("""
DROP FUNCTION my_lower(s: std::str);
""")
await self.con.execute("""
CREATE FUNCTION my_lower(s: SET OF anytype)
-> std::str {
USING SQL FUNCTION 'count';
SET initial_value := '';
};
""")
with self.assertRaisesRegex(edgedb.DuplicateFunctionDefinitionError,
r'cannot create.*my_lower.*func'):
async with self.con.transaction():
await self.con.execute("""
CREATE FUNCTION my_lower(s: anytype) -> std::str
USING SQL FUNCTION 'lower';
""")
await self.con.execute("""
DROP FUNCTION my_lower(s: anytype);
""") | )
with self.assertRaisesRegex(edgedb.DuplicateFunctionDefinitionError,
r'cannot create.*my_lower.*func'):
async with self.con.transaction():
await self.con.execute( | test_edgeql_ddl_function_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_02(self):
long_func_name = 'my_sql_func5_' + 'abc' * 50
await self.con.execute(f"""
CREATE FUNCTION my_sql_func1()
-> std::str
USING SQL $$
SELECT 'spam'::text
$$;
CREATE FUNCTION my_sql_func2(foo: std::str)
-> std::str
USING SQL $$
SELECT "foo"::text
$$;
CREATE FUNCTION my_sql_func4(VARIADIC s: std::str)
-> std::str
USING SQL $$
SELECT array_to_string(s, '-')
$$;
CREATE FUNCTION {long_func_name}()
-> std::str
USING SQL $$
SELECT '{long_func_name}'::text
$$;
CREATE FUNCTION my_sql_func6(a: std::str='a' ++ 'b')
-> std::str
USING SQL $$
SELECT $1 || 'c'
$$;
CREATE FUNCTION my_sql_func7(s: array<std::int64>)
-> std::int64
USING SQL $$
SELECT sum(s)::bigint FROM UNNEST($1) AS s
$$;
""")
await self.assert_query_result(
r"""
SELECT my_sql_func1();
""",
['spam'],
)
await self.assert_query_result(
r"""
SELECT my_sql_func2('foo');
""",
['foo'],
)
await self.assert_query_result(
r"""
SELECT my_sql_func4('fizz', 'buzz');
""",
['fizz-buzz'],
)
await self.assert_query_result(
fr"""
SELECT {long_func_name}();
""",
[long_func_name],
)
await self.assert_query_result(
r"""
SELECT my_sql_func6();
""",
['abc'],
)
await self.assert_query_result(
r"""
SELECT my_sql_func6('xy');
""",
['xyc'],
)
await self.assert_query_result(
r"""
SELECT my_sql_func7([1, 2, 3, 10]);
""",
[16],
)
await self.con.execute(f"""
DROP FUNCTION my_sql_func1();
DROP FUNCTION my_sql_func2(foo: std::str);
DROP FUNCTION my_sql_func4(VARIADIC s: std::str);
DROP FUNCTION {long_func_name}();
DROP FUNCTION my_sql_func6(a: std::str='a' ++ 'b');
DROP FUNCTION my_sql_func7(s: array<std::int64>);
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_function_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_04(self):
await self.con.execute(f"""
CREATE FUNCTION my_edgeql_func1()
-> std::str
USING EdgeQL $$
SELECT 'sp' ++ 'am'
$$;
CREATE FUNCTION my_edgeql_func2(s: std::str)
-> OPTIONAL schema::ObjectType
USING EdgeQL $$
SELECT
schema::ObjectType
FILTER schema::ObjectType.name = s
LIMIT 1
$$;
CREATE FUNCTION my_edgeql_func3(s: std::int64)
-> std::int64
USING EdgeQL $$
SELECT s + 10
$$;
CREATE FUNCTION my_edgeql_func4(i: std::int64)
-> array<std::int64>
USING EdgeQL $$
SELECT [i, 1, 2, 3]
$$;
""")
await self.assert_query_result(
r"""
SELECT my_edgeql_func1();
""",
['spam'],
)
await self.assert_query_result(
r"""
SELECT my_edgeql_func2('schema::Object').name;
""",
['schema::Object'],
)
await self.assert_query_result(
r"""
SELECT (SELECT my_edgeql_func2('schema::Object')).name;
""",
['schema::Object'],
)
await self.assert_query_result(
r"""
SELECT my_edgeql_func3(1);
""",
[11],
)
await self.assert_query_result(
r"""
SELECT my_edgeql_func4(42);
""",
[[42, 1, 2, 3]]
)
await self.con.execute(f"""
DROP FUNCTION my_edgeql_func1();
DROP FUNCTION my_edgeql_func2(s: std::str);
DROP FUNCTION my_edgeql_func3(s: std::int64);
DROP FUNCTION my_edgeql_func4(i: std::int64);
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_function_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_05(self):
await self.con.execute("""
CREATE FUNCTION attr_func_1() -> std::str {
CREATE ANNOTATION description := 'hello';
USING EdgeQL "SELECT '1'";
};
""")
await self.assert_query_result(
r"""
SELECT schema::Function {
annotations: {
@value
} FILTER .name = 'std::description'
} FILTER .name = 'default::attr_func_1';
""",
[{
'annotations': [{
'@value': 'hello'
}]
}],
)
await self.con.execute("""
DROP FUNCTION attr_func_1();
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_function_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_06(self):
await self.con.execute("""
CREATE FUNCTION int_func_1() -> std::int64 {
USING EdgeQL "SELECT 1";
};
""")
await self.assert_query_result(
r"""
SELECT int_func_1();
""",
[1],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_08(self):
async with self.assertRaisesRegexTx(
edgedb.InvalidFunctionDefinitionError,
r'invalid declaration.*unexpected type of the default'):
await self.con.execute("""
CREATE FUNCTION ddlf_08(s: std::str = 1) -> std::str
USING EdgeQL $$ SELECT "1" $$;
""")
async with self.assertRaisesRegexTx(
edgedb.InvalidFunctionDefinitionError,
r'invalid declaration.*unexpected type of the default'):
await self.con.execute("""
CREATE FUNCTION ddlf_08(s: std::str = ()) -> std::str
USING EdgeQL $$ SELECT "1" $$;
""") | )
async with self.assertRaisesRegexTx(
edgedb.InvalidFunctionDefinitionError,
r'invalid declaration.*unexpected type of the default'):
await self.con.execute( | test_edgeql_ddl_function_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_09(self):
await self.con.execute("""
CREATE FUNCTION ddlf_09(
NAMED ONLY a: int64,
NAMED ONLY b: int64
) -> std::str
USING EdgeQL $$ SELECT "1" $$;
""")
with self.assertRaisesRegex(
edgedb.DuplicateFunctionDefinitionError,
r'already defined'):
async with self.con.transaction():
await self.con.execute("""
CREATE FUNCTION ddlf_09(
NAMED ONLY b: int64,
NAMED ONLY a: int64 = 1
) -> std::str
USING EdgeQL $$ SELECT "1" $$;
""")
await self.con.execute("""
CREATE FUNCTION ddlf_09(
NAMED ONLY b: str,
NAMED ONLY a: int64
) -> std::str
USING EdgeQL $$ SELECT "2" $$;
""")
await self.assert_query_result(
r'''
SELECT ddlf_09(a:=1, b:=1);
''',
['1'],
)
await self.assert_query_result(
r'''
SELECT ddlf_09(a:=1, b:='a');
''',
['2'],
) | )
with self.assertRaisesRegex(
edgedb.DuplicateFunctionDefinitionError,
r'already defined'):
async with self.con.transaction():
await self.con.execute( | test_edgeql_ddl_function_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_11(self):
await self.con.execute(r'''
CREATE FUNCTION ddlf_11_1() -> str
USING EdgeQL $$
SELECT '\u0062'
$$;
CREATE FUNCTION ddlf_11_2() -> str
USING EdgeQL $$
SELECT r'\u0062'
$$;
CREATE FUNCTION ddlf_11_3() -> str
USING EdgeQL $$
SELECT $a$\u0062$a$
$$;
''')
try:
await self.assert_query_result(
r'''
SELECT ddlf_11_1();
''',
['b'],
)
await self.assert_query_result(
r'''
SELECT ddlf_11_2();
''',
[r'\u0062'],
)
await self.assert_query_result(
r'''
SELECT ddlf_11_3();
''',
[r'\u0062'],
)
finally:
await self.con.execute("""
DROP FUNCTION ddlf_11_1();
DROP FUNCTION ddlf_11_2();
DROP FUNCTION ddlf_11_3();
""") | )
try:
await self.assert_query_result(
r | test_edgeql_ddl_function_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_13(self):
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
r'cannot create.*ddlf_13\(a: SET OF std::int64\).*'
r'SET OF parameters in user-defined EdgeQL functions are '
r'not supported'):
async with self.con.transaction():
await self.con.execute(r'''
CREATE FUNCTION ddlf_13(a: SET OF int64) -> int64
USING EdgeQL $$ SELECT 11 $$;
''')
with self.assertRaises(edgedb.InvalidReferenceError):
await self.con.execute("""
DROP FUNCTION ddlf_13(a: SET OF int64);
""") | )
with self.assertRaises(edgedb.InvalidReferenceError):
await self.con.execute( | test_edgeql_ddl_function_13 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_14(self):
await self.con.execute(r'''
CREATE FUNCTION ddlf_14(
a: int64, NAMED ONLY f: int64) -> int64
USING EdgeQL $$ SELECT 11 $$;
CREATE FUNCTION ddlf_14(
a: int32, NAMED ONLY f: str) -> int64
USING EdgeQL $$ SELECT 12 $$;
''')
try:
await self.assert_query_result(
r'''
SELECT ddlf_14(<int64>10, f := 11);
''',
[11],
)
await self.assert_query_result(
r'''
SELECT ddlf_14(<int32>10, f := '11');
''',
[12],
)
finally:
await self.con.execute("""
DROP FUNCTION ddlf_14(a: int64, NAMED ONLY f: int64);
DROP FUNCTION ddlf_14(a: int32, NAMED ONLY f: str);
""") | )
try:
await self.assert_query_result(
r | test_edgeql_ddl_function_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_17(self):
await self.con.execute(r'''
CREATE FUNCTION ddlf_17(str: std::str) -> int32
USING SQL FUNCTION 'char_length';
''')
with self.assertRaisesRegex(
edgedb.InvalidFunctionDefinitionError,
r'cannot create.*ddlf_17.*'
r'overloading "USING SQL FUNCTION"'):
async with self.con.transaction():
await self.con.execute(r'''
CREATE FUNCTION ddlf_17(str: std::int64) -> int32
USING SQL FUNCTION 'whatever2';
''')
await self.con.execute("""
DROP FUNCTION ddlf_17(str: std::str);
""") | )
with self.assertRaisesRegex(
edgedb.InvalidFunctionDefinitionError,
r'cannot create.*ddlf_17.*'
r'overloading "USING SQL FUNCTION"'):
async with self.con.transaction():
await self.con.execute(r | test_edgeql_ddl_function_17 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_26(self):
await self.con.execute(r"""
CREATE ABSTRACT ANNOTATION foo26;
CREATE FUNCTION edgeql_func26(a: std::str) -> std::str {
USING EdgeQL $$
SELECT a ++ 'aaa'
$$;
# volatility must be case insensitive
SET volatility := 'Volatile';
};
ALTER FUNCTION edgeql_func26(a: std::str) {
CREATE ANNOTATION foo26 := 'aaaa';
};
ALTER FUNCTION edgeql_func26(a: std::str) {
# volatility must be case insensitive
SET volatility := 'immutable';
};
""")
await self.assert_query_result(
r'''
SELECT edgeql_func26('b')
''',
[
'baaa'
],
)
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Function {
name,
annotations: {
name,
@value,
},
vol := <str>.volatility,
}
FILTER
.name = 'default::edgeql_func26';
''',
[
{
'name': 'default::edgeql_func26',
'annotations': [
{
'name': 'default::foo26',
'@value': 'aaaa',
},
],
'vol': 'Immutable',
},
]
)
await self.con.execute(r"""
ALTER FUNCTION edgeql_func26(a: std::str) {
DROP ANNOTATION foo26;
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Function {
name,
annotations: {
name,
@value,
},
}
FILTER
.name = 'default::edgeql_func26';
''',
[
{
'name': 'default::edgeql_func26',
'annotations': [],
},
]
)
await self.con.execute(r"""
ALTER FUNCTION edgeql_func26(a: std::str) {
USING (
SELECT a ++ 'bbb'
)
};
""")
await self.assert_query_result(
r'''
SELECT edgeql_func26('b')
''',
[
'bbbb'
],
)
await self.con.execute(r"""
ALTER FUNCTION edgeql_func26(a: std::str) {
USING EdgeQL $$
SELECT a ++ 'zzz'
$$
};
""")
await self.assert_query_result(
r'''
SELECT edgeql_func26('b')
''',
[
'bzzz'
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_26 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_27(self):
# This test checks constants, but we have to do DDLs to test them
# with constant extraction disabled
await self.con.execute('''
CREATE FUNCTION constant_int() -> std::int64 {
USING (SELECT 1_024);
};
CREATE FUNCTION constant_bigint() -> std::bigint {
USING (SELECT 1_024n);
};
CREATE FUNCTION constant_float() -> std::float64 {
USING (SELECT 1_024.1_250);
};
CREATE FUNCTION constant_decimal() -> std::decimal {
USING (SELECT 1_024.1_024n);
};
''')
try:
await self.assert_query_result(
r'''
SELECT (
int := constant_int(),
bigint := constant_bigint(),
float := constant_float(),
decimal := constant_decimal(),
)
''',
[{
"int": 1024,
"bigint": 1024,
"float": 1024.125,
"decimal": 1024.1024,
}],
[{
"int": 1024,
"bigint": 1024,
"float": 1024.125,
"decimal": decimal.Decimal('1024.1024'),
}],
)
finally:
await self.con.execute("""
DROP FUNCTION constant_int();
DROP FUNCTION constant_float();
DROP FUNCTION constant_bigint();
DROP FUNCTION constant_decimal();
""") | )
try:
await self.assert_query_result(
r | test_edgeql_ddl_function_27 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_31(self):
await self.con.execute(r'''
CREATE FUNCTION foo() -> str USING ('a');
''')
with self.assertRaisesRegex(
edgedb.InvalidFunctionDefinitionError,
r"return type mismatch"):
await self.con.execute(r'''
ALTER FUNCTION foo() USING (1);
''') | )
with self.assertRaisesRegex(
edgedb.InvalidFunctionDefinitionError,
r"return type mismatch"):
await self.con.execute(r | test_edgeql_ddl_function_31 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_32(self):
await self.con.execute(r'''
CREATE TYPE Foo;
CREATE TYPE Bar;
INSERT Foo;
INSERT Bar;
''')
# All these overloads are OK.
await self.con.execute(r"""
CREATE FUNCTION func32_ok(obj: Foo, a: int64) -> str
USING ('Foo int64');
CREATE FUNCTION func32_ok(obj: Bar, a: int64) -> str
USING ('Bar int64');
CREATE FUNCTION func32_ok(s: str, a: int64) -> str
USING ('str int64');
CREATE FUNCTION func32_ok(s: str, a: Foo) -> str
USING ('str Foo');
CREATE FUNCTION func32_ok(s: str, a: Bar) -> str
USING ('str Bar');
CREATE FUNCTION func32_ok(s: str, a: str, b: str) -> str
USING ('str str str');
""")
await self.assert_query_result(
r"""
WITH
Foo := assert_single(Foo),
Bar := assert_single(Bar),
SELECT {
Foo_int64 := func32_ok(Foo, 1),
Bar_int64 := func32_ok(Bar, 1),
str_int64 := func32_ok("a", 1),
str_Foo := func32_ok("a", Foo),
str_Bar := func32_ok("a", Bar),
str_str_str := func32_ok("a", "b", "c"),
}
""",
[{
"Foo_int64": "Foo int64",
"Bar_int64": "Bar int64",
"str_int64": "str int64",
"str_Foo": "str Foo",
"str_Bar": "str Bar",
"str_str_str": "str str str",
}]
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: overloading an object "
r"type-receiving function with differences in the remaining "
r"parameters is not supported",
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: Foo, a: int32) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: Bar, a: int64) -> str
USING ('bar');
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: overloading an object "
r"type-receiving function with differences in the remaining "
r"parameters is not supported",
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: Foo, obj2: Bar) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: Bar, obj2: Foo) -> str
USING ('bar');
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: overloading an object "
r"type-receiving function with differences in the remaining "
r"parameters is not supported",
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: Foo, a: int32, b: int64) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: Bar, a: int32) -> str
USING ('bar');
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: overloading an object "
r"type-receiving function with differences in the names "
r"of parameters is not supported",
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: Foo, a: int32) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: Bar, b: int32) -> str
USING ('bar');
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: overloading an object "
r"type-receiving function with differences in the type modifiers "
r"of parameters is not supported",
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: Foo, a: int32) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: Bar, a: OPTIONAL int32) -> str
USING ('bar');
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot create the .* function: object "
r"type-receiving functions may not be overloaded on an OPTIONAL "
r"parameter"
):
await self.con.execute(r"""
CREATE FUNCTION func32_a(obj: OPTIONAL Foo) -> str
USING ('foo');
CREATE FUNCTION func32_a(obj: OPTIONAL Bar) -> str
USING ('bar');
""") | )
# All these overloads are OK.
await self.con.execute(r | test_edgeql_ddl_function_32 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_33(self):
await self.con.execute(r"""
CREATE TYPE Parent;
CREATE TYPE Foo EXTENDING Parent;
CREATE TYPE Bar EXTENDING Parent;
INSERT Foo;
INSERT Bar;
CREATE FUNCTION func33(obj: Parent) -> str USING ('parent');
CREATE FUNCTION func33(obj: Foo) -> str USING ('foo');
CREATE FUNCTION func33(obj: Bar) -> str USING ('bar');
""")
await self.assert_query_result(
r"""
SELECT {
foo := assert_single(func33(Foo)),
bar := assert_single(func33(Bar)),
}
""",
[{
"foo": "foo",
"bar": "bar",
}],
)
await self.con.execute(r'''
CREATE TYPE Baz EXTENDING Parent;
INSERT Baz;
''')
# Baz haven't got a specific overload, so it defaults to
# Parent's implementation.
await self.assert_query_result(
r"""
SELECT {
baz := assert_single(func33(Baz)),
}
""",
[{
"baz": "parent",
}],
)
await self.con.execute(r"""
CREATE FUNCTION func33(obj: Baz) -> str USING ('baz');
""")
# There is a specific impl now.
await self.assert_query_result(
r"""
SELECT {
baz := assert_single(func33(Baz)),
}
""",
[{
"baz": "baz",
}],
)
await self.con.execute(r"""
DROP FUNCTION func33(obj: Baz);
""")
# Now there isn't.
await self.assert_query_result(
r"""
SELECT {
foo := assert_single(func33(Foo)),
bar := assert_single(func33(Bar)),
baz := assert_single(func33(Baz)),
}
""",
[{
"foo": "foo",
"bar": "bar",
"baz": "parent",
}],
)
await self.con.execute(r'''
CREATE TYPE PriorityParent;
ALTER TYPE Baz EXTENDING PriorityParent FIRST;
CREATE FUNCTION func33(obj: PriorityParent) -> str
USING ('priority parent');
''')
# Now there is a new parent earlier in ancestor resolution order.
await self.assert_query_result(
r"""
SELECT {
foo := assert_single(func33(Foo)),
bar := assert_single(func33(Bar)),
baz := assert_single(func33(Baz)),
}
""",
[{
"foo": "foo",
"bar": "bar",
"baz": "priority parent",
}],
)
# Test that named-only stuff works just as well.
await self.con.execute(
r"""
CREATE FUNCTION func33_no(NAMED ONLY obj: Parent) -> str
USING ('parent');
CREATE FUNCTION func33_no(NAMED ONLY obj: Foo) -> str
USING ('foo');
CREATE FUNCTION func33_no(NAMED ONLY obj: Bar) -> str
USING ('bar');
""",
)
await self.assert_query_result(
r"""
SELECT {
foo := assert_single(func33_no(obj := Foo)),
bar := assert_single(func33_no(obj := Bar)),
baz := assert_single(func33_no(obj := Baz)),
}
""",
[{
"foo": "foo",
"bar": "bar",
"baz": "parent",
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_33 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_37(self):
obj = await self.con.query_single('''
create type X;
create function getUser(id: uuid) -> set of X {
using(
select X filter .id = id
)
};
insert X;
insert X;
''')
val = await self.con.query_single(
'''
select count(getUser(<uuid>$0))
''',
obj.id,
)
self.assertEqual(val, 1) | )
val = await self.con.query_single( | test_edgeql_ddl_function_37 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_39(self):
'''
Creating a function operating on or returning an array of valid
scalars.
'''
await self.con.execute('''
create function get_singleton(
a: array<range<int64>>
) -> array<range<int64>> using(
a[:1]
);
''')
await self.assert_query_result(
r'''
select get_singleton([range(1, 3), range(1, 2)]) =
[range(1, 3)];
''',
[True]
) | Creating a function operating on or returning an array of valid
scalars. | test_edgeql_ddl_function_39 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_40(self):
'''
Overloading with a modifying function.
'''
await self.con.execute('''
create type Bar;
create type Bar2 extending Bar;
create function foo(x: Bar) -> int64 {
using (1);
};
''')
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
'cannot overload an existing function with a modifying function',
):
await self.con.execute('''
create function foo(x: Bar2) -> int64 {
set volatility := schema::Volatility.Modifying;
using (1);
};
''') | Overloading with a modifying function. | test_edgeql_ddl_function_40 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_41(self):
'''
Overloading a modifying function.
'''
await self.con.execute('''
create type Bar;
create type Bar2 extending Bar;
create function foo(x: Bar) -> int64 {
set volatility := schema::Volatility.Modifying;
using (1);
};
''')
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
'cannot overload an existing modifying function',
):
await self.con.execute('''
create function foo(x: Bar2) -> int64 {
using (1);
};
''') | Overloading a modifying function. | test_edgeql_ddl_function_41 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_inh_01(self):
await self.con.execute("""
create abstract type T;
create function countall() -> int64 USING (count(T));
""")
await self.assert_query_result(
"""SELECT countall()""",
[0],
)
await self.con.execute("""
create type S1 extending T;
insert S1;
""")
await self.assert_query_result(
"""SELECT countall()""",
[1],
)
await self.con.execute("""
create type S2 extending T;
insert S2;
insert S2;
""")
await self.assert_query_result(
"""SELECT countall()""",
[3],
)
await self.con.execute("""
drop type S2;
""")
await self.assert_query_result(
"""SELECT countall()""",
[1],
) | )
await self.assert_query_result(
"""SELECT countall()""",
[0],
)
await self.con.execute( | test_edgeql_ddl_function_inh_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_inh_02(self):
await self.con.execute("""
create abstract type T { create multi property n -> int64 };
create function countall() -> int64 USING (sum(T.n));
""")
await self.assert_query_result(
"""SELECT countall()""",
[0],
)
await self.con.execute("""
create type S1 extending T;
insert S1 { n := {3, 4} };
""")
await self.assert_query_result(
"""SELECT countall()""",
[7],
)
await self.con.execute("""
create type S2 extending T;
insert S2 { n := 1 };
insert S2 { n := {2, 2, 2} };
""")
await self.assert_query_result(
"""SELECT countall()""",
[14],
)
await self.con.execute("""
drop type S2;
""")
await self.assert_query_result(
"""SELECT countall()""",
[7],
) | )
await self.assert_query_result(
"""SELECT countall()""",
[0],
)
await self.con.execute( | test_edgeql_ddl_function_inh_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_01(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
}
""")
await self.assert_query_result(
"""SELECT foo("a")""",
["a"],
)
await self.con.execute("""
ALTER FUNCTION foo(s: str)
RENAME TO bar;
""")
await self.assert_query_result(
"""SELECT bar("a")""",
["a"],
)
await self.con.execute("""
DROP FUNCTION bar(s: str)
""") | )
await self.assert_query_result(
"""SELECT foo("a")""",
["a"],
)
await self.con.execute( | test_edgeql_ddl_function_rename_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_02(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
};
CREATE FUNCTION bar(s: int64) -> str {
USING (SELECT <str>s)
};
""")
with self.assertRaisesRegex(
edgedb.SchemaError,
r"can not rename function to 'default::foo' because "
r"a function with the same name already exists"):
await self.con.execute("""
ALTER FUNCTION bar(s: int64)
RENAME TO foo;
""") | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r"can not rename function to 'default::foo' because "
r"a function with the same name already exists"):
await self.con.execute( | test_edgeql_ddl_function_rename_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_03(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
};
CREATE FUNCTION foo(s: int64) -> str {
USING (SELECT <str>s)
};
""")
with self.assertRaisesRegex(
edgedb.SchemaError,
r"renaming an overloaded function is not allowed"):
await self.con.execute("""
ALTER FUNCTION foo(s: int64)
RENAME TO bar;
""") | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r"renaming an overloaded function is not allowed"):
await self.con.execute( | test_edgeql_ddl_function_rename_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_04(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
};
CREATE MODULE foo;
""")
await self.assert_query_result(
"""SELECT foo("a")""",
["a"],
)
await self.con.execute("""
ALTER FUNCTION foo(s: str)
RENAME TO foo::bar;
""")
await self.assert_query_result(
"""SELECT foo::bar("a")""",
["a"],
)
await self.con.execute("""
DROP FUNCTION foo::bar(s: str)
""") | )
await self.assert_query_result(
"""SELECT foo("a")""",
["a"],
)
await self.con.execute( | test_edgeql_ddl_function_rename_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_05(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
};
CREATE FUNCTION call(s: str) -> str {
USING (SELECT foo(s))
};
""")
await self.con.execute("""
ALTER FUNCTION foo(s: str) RENAME TO bar;
""")
await self.assert_query_result(
"""SELECT call("a")""",
["a"],
) | )
await self.con.execute( | test_edgeql_ddl_function_rename_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_rename_06(self):
await self.con.execute("""
CREATE FUNCTION foo(s: str) -> str {
USING (SELECT s)
};
CREATE FUNCTION call(s: str) -> str {
USING (SELECT foo(s))
};
""")
await self.con.execute("""
CREATE MODULE foo;
ALTER FUNCTION foo(s: str) RENAME TO foo::foo;
""")
await self.assert_query_result(
"""SELECT call("a")""",
["a"],
) | )
await self.con.execute( | test_edgeql_ddl_function_rename_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_01(self):
await self.con.execute('''
CREATE FUNCTION foo() -> int64 {
USING (SELECT 1)
}
''')
await self.assert_query_result(
r'''
SELECT schema::Function { volatility }
FILTER .name = 'default::foo';
''',
[{
"volatility": "Immutable",
}]
)
await self.assert_query_result(
'''SELECT (foo(), {1,2})''',
[[1, 1], [1, 2]]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_volatility_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_02(self):
await self.con.execute('''
CREATE FUNCTION foo() -> int64 {
USING (SELECT <int64>random())
}
''')
await self.assert_query_result(
r'''
SELECT schema::Function {volatility}
FILTER .name = 'default::foo';
''',
[{
"volatility": "Volatile",
}]
)
with self.assertRaisesRegex(
edgedb.QueryError,
r"can not take cross product of volatile operation"):
await self.con.query(
'''SELECT (foo(), {1,2})'''
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_volatility_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_03(self):
await self.con.execute('''
CREATE FUNCTION foo() -> int64 {
USING (SELECT 1);
SET volatility := "volatile";
}
''')
await self.assert_query_result(
r'''
SELECT schema::Function {volatility}
FILTER .name = 'default::foo';
''',
[{
"volatility": "Volatile",
}]
)
with self.assertRaisesRegex(
edgedb.QueryError,
r"can not take cross product of volatile operation"):
await self.con.query(
'''SELECT (foo(), {1,2})'''
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_volatility_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_06(self):
await self.con.execute('''
CREATE FUNCTION foo() -> float64 {
USING (1);
};
CREATE FUNCTION bar() -> float64 {
USING (foo());
};
''')
await self.assert_query_result(
r'''
SELECT schema::Function {name, volatility}
FILTER .name LIKE 'default::%'
ORDER BY .name;
''',
[
{"name": "default::bar", "volatility": "Immutable"},
{"name": "default::foo", "volatility": "Immutable"},
]
)
await self.con.execute('''
ALTER FUNCTION foo() SET volatility := "stable";
''')
await self.assert_query_result(
r'''
SELECT schema::Function {name, volatility, computed_fields}
FILTER .name LIKE 'default::%'
ORDER BY .name;
''',
[
{"name": "default::bar", "volatility": "Stable",
"computed_fields": ["volatility"]},
{"name": "default::foo", "volatility": "Stable",
"computed_fields": []},
]
)
await self.con.execute('''
ALTER FUNCTION foo() {
RESET volatility;
}
''')
await self.assert_query_result(
r'''
SELECT schema::Function {name, volatility, computed_fields}
FILTER .name LIKE 'default::%'
ORDER BY .name;
''',
[
{"name": "default::bar", "volatility": "Immutable",
"computed_fields": ["volatility"]},
{"name": "default::foo", "volatility": "Immutable",
"computed_fields": ["volatility"]},
]
)
await self.con.execute('''
ALTER FUNCTION foo() {
RESET volatility;
USING (random());
}
''')
await self.assert_query_result(
r'''
SELECT schema::Function {name, volatility}
FILTER .name LIKE 'default::%'
ORDER BY .name;
''',
[
{"name": "default::bar", "volatility": "Volatile"},
{"name": "default::foo", "volatility": "Volatile"},
]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_volatility_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_07(self):
await self.con.execute('''
CREATE FUNCTION foo() -> float64 {
USING (1);
};
CREATE FUNCTION bar() -> float64 {
USING (foo());
};
CREATE FUNCTION baz() -> float64 {
USING (bar());
};
''')
# Test that the alter propagates multiple times
await self.con.execute('''
ALTER FUNCTION foo() SET volatility := "stable";
''')
await self.assert_query_result(
r'''
SELECT schema::Function {name, volatility}
FILTER .name LIKE 'default::%'
ORDER BY .name;
''',
[
{"name": "default::bar", "volatility": "Stable"},
{"name": "default::baz", "volatility": "Stable"},
{"name": "default::foo", "volatility": "Stable"},
]
) | )
# Test that the alter propagates multiple times
await self.con.execute( | test_edgeql_ddl_function_volatility_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_08(self):
await self.con.execute('''
CREATE FUNCTION foo() -> float64 {
USING (1);
};
CREATE FUNCTION bar() -> float64 {
SET volatility := "stable";
USING (foo());
};
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"cannot alter function 'default::foo\(\)' because this affects "
r".*function 'default::bar\(\)'",
):
await self.con.execute('''
ALTER FUNCTION foo() SET volatility := "volatile";
''') | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"cannot alter function 'default::foo\(\)' because this affects "
r".*function 'default::bar\(\)'",
):
await self.con.execute( | test_edgeql_ddl_function_volatility_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_volatility_09(self):
await self.con.execute('''
CREATE TYPE FuncVol { CREATE REQUIRED PROPERTY i -> int64 };
CREATE FUNCTION obj_func(obj: FuncVol) -> int64 {
USING (obj.i)
};
CREATE FUNCTION obj_func_tuple(
obj: tuple<array<FuncVol>>
) -> SET OF int64 {
USING (array_unpack(obj.0).i)
};
CREATE FUNCTION obj_func_tuple_not_referring(
arg: tuple<array<FuncVol>, int64>
) -> int64 {
USING (arg.1)
};
CREATE FUNCTION obj_func_const(obj: FuncVol) -> int64 {
USING (1)
};
''')
await self.assert_query_result(
r'''
SELECT schema::Function { name, volatility }
FILTER .name LIKE 'default::obj_func%'
ORDER BY .name;
''',
[{
"name": "default::obj_func",
"volatility": "Stable",
}, {
"name": "default::obj_func_const",
"volatility": "Immutable",
}, {
"name": "default::obj_func_tuple",
"volatility": "Stable",
}, {
"name": "default::obj_func_tuple_not_referring",
"volatility": "Immutable",
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_function_volatility_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_fallback_02(self):
await self.con.execute(r'''
CREATE FUNCTION foo(a: int64) -> str {
USING (SELECT 'foo' ++ <str>(a + 1));
};
CREATE FUNCTION foo(a: bytes) -> str {
USING (SELECT 'foobytes' ++ <str>len(a));
};
CREATE FUNCTION foo(a: array<anytype>) -> str {
USING (SELECT 'fooarray' ++ <str>len(a));
};
CREATE FUNCTION foo(a: anytype) -> str {
USING (SELECT 'foo' ++ <str>a);
};
''')
await self.con.execute(r'''
ALTER FUNCTION foo(a: array<anytype>) {
SET fallback := true;
};
''')
with self.assertRaisesRegex(
edgedb.InvalidFunctionDefinitionError,
r'cannot alter.*foo\(a: anytype\).*'
r'only one generic fallback per polymorphic function '
r'is allowed'):
await self.con.execute(r'''
ALTER FUNCTION foo(a: anytype) {
SET fallback := true;
};
''') | )
await self.con.execute(r | test_edgeql_ddl_function_fallback_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_recompile_01(self):
# Test that we recompile functions as things change
await self.con.execute('''
create alias X0 := '1';
create alias X := X0;
create global Y -> str { set default := '2' };
create type Z { create property p := '3' };
insert Z;
create function W() -> str using ('4');
create function V0() -> str {
set is_inlined := true;
using ('5')
};
create function V() -> str using (V0());
create function inner() -> set of str using (
X ++ (global Y) ++ Z.p ++ W() ++ V()
);
create function test() -> set of str using (inner());
''')
await self.assert_query_result(
'select test()',
['12345']
)
await self.con.execute('''
alter alias X0 using ('A');
''')
await self.assert_query_result(
'select test()',
['A2345']
)
await self.con.execute('''
alter global Y { set default := 'B' };
''')
await self.assert_query_result(
'select test()',
['AB345']
)
await self.con.execute('''
alter type Z alter property p using ('C');
''')
await self.assert_query_result(
'select test()',
['ABC45']
)
await self.con.execute('''
alter function W() {
using ('D')
};
''')
await self.assert_query_result(
'select test()',
['ABCD5']
)
await self.con.execute('''
alter function V0() {
using ('E')
};
''')
await self.assert_query_result(
'select test()',
['ABCDE']
)
# Check changing inner function to inlined
await self.con.execute('''
alter function inner() {
set is_inlined := true;
using (X ++ (global Y) ++ Z.p ++ W() ++ V() ++ '!');
};
''')
await self.assert_query_result(
'select test()',
['ABCDE!']
) | )
await self.assert_query_result(
'select test()',
['12345']
)
await self.con.execute( | test_edgeql_ddl_function_recompile_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_recompile_02(self):
# Test that we recompile functions as things change
# Changes indirectly via inlined function
await self.con.execute('''
create alias X0 := '1';
create alias X := X0;
create global Y -> str { set default := '2' };
create type Z { create property p := '3' };
insert Z;
create function W() -> str using ('4');
create function V0() -> str {
set is_inlined := true;
using ('5')
};
create function V() -> str using (V0());
create function inner() -> set of str {
set is_inlined := true;
using (X ++ (global Y) ++ Z.p ++ W() ++ V())
};
create function test() -> set of str using (inner());
''')
await self.assert_query_result(
'select test()',
['12345']
)
await self.con.execute('''
alter alias X0 using ('A');
''')
await self.assert_query_result(
'select test()',
['A2345']
)
await self.con.execute('''
alter global Y { set default := 'B' };
''')
await self.assert_query_result(
'select test()',
['AB345']
)
await self.con.execute('''
alter type Z alter property p using ('C');
''')
await self.assert_query_result(
'select test()',
['ABC45']
)
await self.con.execute('''
alter function W() {
using ('D')
};
''')
await self.assert_query_result(
'select test()',
['ABCD5']
)
await self.con.execute('''
alter function V0() {
using ('E')
};
''')
await self.assert_query_result(
'select test()',
['ABCDE']
)
# Check changing inner function from inlined
await self.con.execute('''
alter function inner() {
set is_inlined := false;
using (X ++ (global Y) ++ Z.p ++ W() ++ V() ++ '!');
};
''')
await self.assert_query_result(
'select test()',
['ABCDE!']
) | )
await self.assert_query_result(
'select test()',
['12345']
)
await self.con.execute( | test_edgeql_ddl_function_recompile_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_function_recompile_03(self):
# Check that modifying functions are recompiled
await self.con.execute('''
create type Bar { create property a -> int64 };
create function inner(x: int64) -> Bar using ((
insert Bar { a := x }
));
create function test(x: int64) -> Bar using (inner(x));
''')
await self.assert_query_result(
'select test(1).a',
[1],
)
await self.assert_query_result(
'select Bar.a',
[1],
)
await self.con.execute('''
alter function test(x: int64) {
using ((insert Bar { a := x + 10 }));
};
''')
await self.assert_query_result(
'select test(2).a',
[12],
)
await self.assert_query_result(
'select Bar.a',
[1, 12],
sort=True,
) | )
await self.assert_query_result(
'select test(1).a',
[1],
)
await self.assert_query_result(
'select Bar.a',
[1],
)
await self.con.execute( | test_edgeql_ddl_function_recompile_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_module_04(self):
async with self.assertRaisesRegexTx(
edgedb.UnknownModuleError,
"module 'foo' is not in this schema"):
await self.con.execute('''\
CREATE MODULE foo::bar;
''')
await self.con.execute('''\
CREATE MODULE foo;
CREATE MODULE foo::bar;
CREATE TYPE foo::Foo;
CREATE TYPE foo::bar::Baz;
''')
await self.assert_query_result(
r'''
select foo::bar::Baz
''',
[]
)
await self.assert_query_result(
r'''
with module foo::bar
select Baz
''',
[]
)
await self.con.execute('''\
SET MODULE foo::bar;
''')
await self.assert_query_result(
r'''
select foo::bar::Baz
''',
[]
)
await self.assert_query_result(
r'''
select Baz
''',
[]
)
await self.con.execute('''\
SET MODULE foo;
''')
# We *don't* support relative references of submodules
async with self.assertRaisesRegexTx(
edgedb.InvalidReferenceError,
"'bar::Baz' does not exist"):
await self.con.execute('''\
SELECT bar::Baz
''')
await self.assert_query_result(
r'''
select Foo
''',
[]
)
await self.con.execute('''\
RESET MODULE;
''')
# We *don't* support relative references of submodules
async with self.assertRaisesRegexTx(
edgedb.InvalidReferenceError,
"'bar::Baz' does not exist"):
await self.con.execute('''\
WITH MODULE foo
SELECT bar::Baz
''')
await self.assert_query_result(
r'''
with m as module foo::bar
select m::Baz
''',
[]
)
await self.assert_query_result(
r'''
with m as module foo
select m::bar::Baz
''',
[]
) | )
await self.con.execute('''\
CREATE MODULE foo;
CREATE MODULE foo::bar;
CREATE TYPE foo::Foo;
CREATE TYPE foo::bar::Baz;
''')
await self.assert_query_result(
r | test_edgeql_ddl_module_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_module_05(self):
await self.con.execute('''\
CREATE MODULE foo;
CREATE MODULE foo::bar;
SET MODULE foo::bar;
CREATE TYPE Baz;
''')
await self.assert_query_result(
r'''
select foo::bar::Baz
''',
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_module_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_operator_01(self):
await self.con.execute('''
CREATE INFIX OPERATOR `+++`
(left: int64, right: int64) -> int64
{
SET commutator := 'default::+++';
USING SQL OPERATOR r'+';
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Operator {
name,
params: {
name,
type: {
name
},
typemod
} ORDER BY .name,
operator_kind,
return_typemod
}
FILTER
.name = 'default::+++';
''',
[{
'name': 'default::+++',
'params': [
{
'name': 'left',
'type': {
'name': 'std::int64'
},
'typemod': 'SingletonType'
},
{
'name': 'right',
'type': {
'name': 'std::int64'
},
'typemod': 'SingletonType'}
],
'operator_kind': 'Infix',
'return_typemod': 'SingletonType'
}]
)
await self.con.execute('''
ALTER INFIX OPERATOR `+++`
(left: int64, right: int64)
CREATE ANNOTATION description := 'my plus';
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Operator {
name,
}
FILTER
.name = 'default::+++'
AND any(
.annotations.name = 'std::description'
AND .annotations@value = 'my plus'
);
''',
[{
'name': 'default::+++',
}]
)
await self.con.execute("""
DROP INFIX OPERATOR `+++` (left: int64, right: int64);
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Operator {
name,
params: {
name,
type: {
name
},
typemod
},
operator_kind,
return_typemod
}
FILTER
.name = 'default::+++';
''',
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_operator_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_operator_02(self):
try:
await self.con.execute('''
CREATE PREFIX OPERATOR `!`
(operand: int64) -> int64
{
USING SQL OPERATOR r'+';
};
CREATE INFIX OPERATOR `!`
(l: int64, r: int64) -> int64
{
SET commutator := 'default::!';
USING SQL OPERATOR r'+';
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Operator {
name,
operator_kind,
}
FILTER
.name = 'default::!'
ORDER BY
.operator_kind;
''',
[
{
'name': 'default::!',
'operator_kind': 'Infix',
},
{
'name': 'default::!',
'operator_kind': 'Prefix',
}
]
)
finally:
await self.con.execute('''
DROP INFIX OPERATOR `!`
(l: int64, r: int64);
DROP PREFIX OPERATOR `!`
(operand: int64);
''') | )
await self.assert_query_result(
r | test_edgeql_ddl_operator_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_operator_08(self):
try:
await self.con.execute('''
CREATE ABSTRACT INFIX OPERATOR `>`
(left: anytype, right: anytype) -> bool;
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Operator {
name,
abstract,
}
FILTER
.name = 'default::>'
''',
[
{
'name': 'default::>',
'abstract': True,
},
]
)
finally:
await self.con.execute('''
DROP INFIX OPERATOR `>`
(left: anytype, right: anytype);
''') | )
await self.assert_query_result(
r | test_edgeql_ddl_operator_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_02(self):
await self.con.execute('''
CREATE ABSTRACT SCALAR TYPE a EXTENDING std::int64;
CREATE ABSTRACT SCALAR TYPE b EXTENDING std::str;
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
r'may not have more than one concrete base type'):
await self.con.execute('''
CREATE SCALAR TYPE myint EXTENDING a, b;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r'may not have more than one concrete base type'):
await self.con.execute( | test_edgeql_ddl_scalar_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_03(self):
await self.con.execute('''
CREATE ABSTRACT SCALAR TYPE a EXTENDING std::int64;
CREATE ABSTRACT SCALAR TYPE b EXTENDING std::str;
CREATE SCALAR TYPE myint EXTENDING a;
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type may not have more than one concrete base type'):
await self.con.execute('''
ALTER SCALAR TYPE myint EXTENDING b;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type may not have more than one concrete base type'):
await self.con.execute( | test_edgeql_ddl_scalar_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_04(self):
await self.con.execute('''
CREATE ABSTRACT SCALAR TYPE a;
CREATE SCALAR TYPE myint EXTENDING int64, a;
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type may not have more than one concrete base type'):
await self.con.execute('''
ALTER SCALAR TYPE a EXTENDING str;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type may not have more than one concrete base type'):
await self.con.execute( | test_edgeql_ddl_scalar_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_07(self):
await self.con.execute('''
CREATE SCALAR TYPE a EXTENDING std::str;
CREATE SCALAR TYPE b EXTENDING std::str;
''')
# I think we want to prohibit this kind of diamond pattern
with self.assertRaisesRegex(
edgedb.SchemaError,
r'may not have more than one concrete base type'):
await self.con.execute('''
CREATE SCALAR TYPE myint EXTENDING a, b;
''') | )
# I think we want to prohibit this kind of diamond pattern
with self.assertRaisesRegex(
edgedb.SchemaError,
r'may not have more than one concrete base type'):
await self.con.execute( | test_edgeql_ddl_scalar_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_08(self):
await self.con.execute('''
CREATE SCALAR TYPE myint EXTENDING int64;
CREATE TYPE Bar {
CREATE PROPERTY b1 -> tuple<myint, tuple<myint>>;
CREATE PROPERTY b2 -> tuple<myint, tuple<myint>>;
CREATE MULTI PROPERTY b3 -> tuple<z: myint, y: array<myint>>;
};
CREATE TYPE Foo {
CREATE PROPERTY a1 -> array<myint>;
CREATE PROPERTY a2 -> tuple<array<myint>>;
CREATE PROPERTY a3 -> array<tuple<array<myint>>>;
CREATE PROPERTY a4 -> tuple<myint, str>;
CREATE PROPERTY a5 -> tuple<myint, myint>;
CREATE PROPERTY a6 -> tuple<myint, tuple<myint>>;
CREATE PROPERTY a6b -> tuple<myint, tuple<myint>>;
CREATE LINK l -> Bar {
CREATE PROPERTY l1 -> tuple<str, myint>;
CREATE PROPERTY l2 -> tuple<myint, tuple<myint>>;
};
};
''')
count_query = "SELECT count(schema::CollectionType);"
orig_count = await self.con.query_single(count_query)
await self.con.execute('''
ALTER SCALAR TYPE myint CREATE CONSTRAINT std::one_of(1, 2);
''')
self.assertEqual(await self.con.query_single(count_query), orig_count)
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'myint must be one of'):
await self.con.execute('''
INSERT Foo { a4 := (10, "oops") };
''')
await self.con.execute('''
INSERT Foo { a3 := [([2],)] };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'myint must be one of:'):
await self.con.execute('''
ALTER SCALAR TYPE myint DROP CONSTRAINT std::one_of(1, 2);
ALTER SCALAR TYPE myint CREATE CONSTRAINT std::one_of(1);
''') | )
count_query = "SELECT count(schema::CollectionType);"
orig_count = await self.con.query_single(count_query)
await self.con.execute( | test_edgeql_ddl_scalar_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_09(self):
# We need to support CREATE FINAL SCALAR for enums because it
# is written out into old migrations.
await self.con.execute('''
CREATE FINAL SCALAR TYPE my_enum EXTENDING enum<'foo', 'bar'>;
''')
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
r'FINAL is not supported'):
await self.con.execute('''
CREATE FINAL SCALAR TYPE myint EXTENDING std::int64;
''') | )
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
r'FINAL is not supported'):
await self.con.execute( | test_edgeql_ddl_scalar_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_11(self):
await self.con.execute('''
create scalar type Foo extending str;
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type must have a concrete base type'):
await self.con.execute('''
alter scalar type Foo drop extending str;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r'scalar type must have a concrete base type'):
await self.con.execute( | test_edgeql_ddl_scalar_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_12(self):
await self.con.execute('''
create scalar type Foo extending str;
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
r'cannot change concrete base of scalar type '
r'default::Foo from std::str to std::int64'):
await self.con.execute('''
alter scalar type Foo {
drop extending str;
extending int64 LAST;
};
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
r'cannot change concrete base of scalar type '
r'default::Foo from std::str to std::int64'):
await self.con.execute( | test_edgeql_ddl_scalar_12 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_13(self):
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r'scalar type may not have a collection base type'):
await self.con.execute('''
create scalar type Foo extending array<str>;
''')
await self.con.execute('''
create scalar type Foo extending str;
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r'scalar type may not have a collection base type',
):
await self.con.execute(
'''
alter scalar type Foo {
drop extending str; extending array<str> last;
};
'''
) | )
await self.con.execute( | test_edgeql_ddl_scalar_13 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_scalar_14(self):
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, r'unsupported range subtype'
):
await self.con.execute(
'''
create scalar type Age extending int16;
create type User {
create property age -> range<Age>;
};
'''
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, r'unsupported range subtype'
):
await self.con.execute(
'''
create type User {
create property age -> range<schema::Object>;
};
'''
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, r'unsupported range subtype'
):
await self.con.execute(
'''
create type User {
create property age -> multirange<int16>;
};
'''
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError, r'unsupported range subtype'
):
await self.con.execute(
'''
create type User {
create property age -> multirange<schema::Object>;
};
'''
) | create scalar type Age extending int16;
create type User {
create property age -> range<Age>;
}; | test_edgeql_ddl_scalar_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_cast_01(self):
await self.con.execute('''
CREATE SCALAR TYPE type_a EXTENDING std::str;
CREATE SCALAR TYPE type_b EXTENDING std::int64;
CREATE SCALAR TYPE type_c EXTENDING std::datetime;
CREATE CAST FROM type_a TO type_b {
USING SQL CAST;
ALLOW IMPLICIT;
};
CREATE CAST FROM type_a TO type_c {
USING SQL CAST;
ALLOW ASSIGNMENT;
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Cast {
from_type: {name},
to_type: {name},
allow_implicit,
allow_assignment,
}
FILTER
.from_type.name LIKE 'default::%'
ORDER BY
.allow_implicit;
''',
[
{
'from_type': {'name': 'default::type_a'},
'to_type': {'name': 'default::type_c'},
'allow_implicit': False,
'allow_assignment': True,
},
{
'from_type': {'name': 'default::type_a'},
'to_type': {'name': 'default::type_b'},
'allow_implicit': True,
'allow_assignment': False,
}
]
)
await self.con.execute("""
DROP CAST FROM type_a TO type_b;
DROP CAST FROM type_a TO type_c;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Cast {
from_type: {name},
to_type: {name},
allow_implicit,
allow_assignment,
}
FILTER
.from_type.name LIKE 'default::%'
ORDER BY
.allow_implicit;
''',
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_cast_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_policies_01(self):
await self.con.execute(r"""
create required global filtering -> bool { set default := false };
create global cur -> str;
create type User {
create required property name -> str;
create access policy all_on allow all using (true);
create access policy filtering
when (global filtering)
deny select, delete using (.name ?!= global cur);
};
create type Bot extending User;
""")
await self.assert_query_result(
'''
select schema::AccessPolicy {
name, condition, expr, action, access_kinds,
sname := .subject.name, root := not exists .bases }
filter .sname like 'default::%'
''',
tb.bag([
{
"access_kinds": {
"Select", "UpdateRead", "UpdateWrite", "Delete",
"Insert"
},
"action": "Allow",
"condition": None,
"expr": "true",
"name": "all_on",
"sname": "default::User",
"root": True,
},
{
"access_kinds": {"Select", "Delete"},
"action": "Deny",
"condition": "global default::filtering",
"expr": "(.name ?!= global default::cur)",
"name": "filtering",
"sname": "default::User",
"root": True,
},
{
"access_kinds": {
"Select", "UpdateRead", "UpdateWrite", "Delete",
"Insert"
},
"action": "Allow",
"condition": None,
"expr": "true",
"name": "all_on",
"sname": "default::Bot",
"root": False,
},
{
"access_kinds": {"Select", "Delete"},
"action": "Deny",
"condition": "global default::filtering",
"expr": "(.name ?!= global default::cur)",
"name": "filtering",
"sname": "default::Bot",
"root": False,
},
])
)
await self.con.execute(r"""
alter type User {
alter access policy filtering {
reset when;
deny select;
using (false);
}
};
""")
await self.assert_query_result(
'''
select schema::AccessPolicy {
name, condition, expr, action, access_kinds,
sname := .subject.name, root := not exists .bases }
filter .sname = 'default::User' and .name = 'filtering'
''',
[
{
"access_kinds": {"Select"},
"action": "Deny",
"condition": None,
"expr": "false",
"name": "filtering",
"sname": "default::User",
"root": True,
},
]
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"cannot alter the definition of inherited access policy",
):
await self.con.execute('''
alter type Bot alter access policy filtering allow all;
''') | )
await self.assert_query_result( | test_edgeql_ddl_policies_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_policies_02(self):
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"when expression.* is of invalid type",
):
await self.con.execute("""
create type X {
create access policy test
when (1)
allow all using (true);
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"using expression.* is of invalid type",
):
await self.con.execute("""
create type X {
create access policy test
allow all using (1);
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"using expression.* is of invalid type",
):
await self.con.execute("""
create type X {
create access policy test
allow all using (());
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly an empty set returned",
):
await self.con.execute("""
create type X {
create property x -> str;
create access policy test
allow all using (.x not like '%redacted%');
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly more than one element returned",
):
await self.con.execute("""
create type X {
create access policy test
allow all using ({true, false});
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"has a volatile using expression",
):
await self.con.execute("""
create type X {
create access policy test
allow all using (random() < 0.5);
};
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"using expression.* is of invalid type",
):
await self.con.execute( | test_edgeql_ddl_policies_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_policies_03(self):
# Ideally we will make this actually work instead of rejecting it!
await self.con.execute("""
CREATE TYPE Tgt;
CREATE TYPE Foo {
CREATE MULTI LINK tgt -> Tgt {
CREATE PROPERTY foo -> str;
};
CREATE ACCESS POLICY asdf
ALLOW ALL USING (all(.tgt@foo LIKE '%!'));
};
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"may not refer to link properties with default values"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK tgt ALTER property foo
SET default := "!!!";
""") | )
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"may not refer to link properties with default values"
):
await self.con.execute( | test_edgeql_ddl_policies_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_policies_04(self):
await self.con.execute("""
create global current_user -> uuid;
create type User {
create access policy ins allow insert;
create access policy sel allow select
using (.id ?= global current_user);
};
create type User2 extending User;
create type Obj {
create optional multi link user -> User;
};
""")
await self.con.execute("""
alter type Obj {
alter link user set required using (select User limit 1);
};
""")
await self.con.execute("""
alter type Obj {
alter link user set single using (select User limit 1);
};
""")
await self.con.execute("""
alter type Obj {
alter link user set type User2 using (select User2 limit 1);
};
""") | )
await self.con.execute( | test_edgeql_ddl_policies_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_func_policies_10(self):
# Make sure we succesfully update multiple functions to thread
# through globals when an access policy is created.
await self.con.execute(r"""
create type X;
insert X;
create function get_xi() -> set of uuid using (X.id);
create function get_x() -> set of uuid using (get_xi());
create required global en -> bool { set default := false };
alter type X {
create access policy test allow select using (global en) };
""")
await self.assert_query_result(
'select get_x()',
[],
)
await self.con.execute('''
set global en := true;
''')
await self.assert_query_result(
'select get_x()',
[str],
) | )
await self.assert_query_result(
'select get_x()',
[],
)
await self.con.execute( | test_edgeql_ddl_func_policies_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_01(self):
INTRO_Q = '''
select schema::Global {
required, typ := .target.name, default }
filter .name = 'default::foo';
'''
await self.con.execute(r"""
create global foo -> str;
""")
await self.assert_query_result(
INTRO_Q,
[{
"required": False,
"typ": "std::str",
"default": None,
}]
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"required globals must have a default",
):
await self.con.execute("""
alter global foo set required;
""")
await self.con.execute(r"""
drop global foo;
create required global foo -> str { set default := "" };
""")
await self.assert_query_result(
INTRO_Q,
[{
"required": True,
"typ": "std::str",
"default": "''",
}]
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"default expression is of invalid type",
):
await self.con.execute("""
alter global foo set type array<uuid> reset to default;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"required globals must have a default",
):
await self.con.execute("""
alter global foo reset default;
""")
await self.con.execute("""
alter global foo set optional;
alter global foo reset default;
alter global foo set type array<int64> reset to default;
""")
await self.assert_query_result(
INTRO_Q,
[{
"required": False,
"typ": "array<std::int64>",
"default": None,
}]
) | await self.con.execute(r | test_edgeql_ddl_global_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_02(self):
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"non-computed globals may not be multi",
):
await self.con.execute("""
create multi global foo -> str;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly more than one element returned",
):
await self.con.execute("""
create global foo -> str {
set default := {"foo", "bar"}
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly no elements returned",
):
await self.con.execute("""
create required global foo -> str {
set default := (select "foo" filter false)
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"non-computed globals may not have have object type",
):
await self.con.execute("""
create global foo -> Object;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"non-computed globals may not have have object type",
):
await self.con.execute("""
create global foo -> array<Object>;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"has a volatile default expression, which is not allowed",
):
await self.con.execute("""
create global foo -> float64 { set default := random(); };
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"computed globals may not have default values",
):
await self.con.execute("""
create global test {
using ('abc');
set default := 'def';
}
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly more than one element returned",
):
await self.con.execute( | test_edgeql_ddl_global_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_03(self):
await self.con.execute("""
create global foo -> str;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"global variables cannot be referenced from constraint"
):
await self.con.execute("""
create type X {
create property foo -> str {
create constraint expression on (
__subject__ != global foo)
}
}
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"global variables cannot be referenced from index"
):
await self.con.execute("""
create type X {
create index on (global foo);
}
""")
await self.con.execute("""
create type X;
""")
await self.con.execute("""
set global foo := "test"
""")
await self.con.execute("""
create type Y {
create property foo -> str {
set default := (global foo);
}
};
""")
await self.con.query("""
insert Y;
""")
await self.assert_query_result(
r'''
select Y.foo
''',
['test']
)
# And when adding a default to an existing column
await self.con.execute("""
alter type X {
create property foo -> str;
};
alter type X {
alter property foo {
set default := (global foo);
}
};
""")
await self.con.query("""
insert X;
""")
await self.assert_query_result(
r'''
select X.foo
''',
['test']
) | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"global variables cannot be referenced from constraint"
):
await self.con.execute( | test_edgeql_ddl_global_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_04(self):
# mostly the same as _03 but with functions
await self.con.execute("""
create global foo -> str;
create function gfoo() -> optional str using (global foo)
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"functions that reference global variables cannot be called "
r"from constraint"
):
await self.con.execute("""
create type X {
create property foo -> str {
create constraint expression on (
__subject__ != gfoo())
}
}
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"functions that reference global variables cannot be called "
r"from index"
):
await self.con.execute("""
create type X {
create index on (gfoo());
}
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"functions that reference global variables cannot be called "
r"from constraint"
):
await self.con.execute( | test_edgeql_ddl_global_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_05(self):
await self.con.execute("""
create global foo -> str;
create function gfoo() -> optional str using ("test");
create function gbar() -> optional str using (gfoo());
""")
await self.con.execute("""
set global foo := "!!"
""")
# test that when we alter a function definition, functions
# that depend on it get updated
await self.con.execute("""
alter function gfoo() using (global foo)
""")
await self.assert_query_result(
r'''select gbar()''',
["!!"],
) | )
await self.con.execute( | test_edgeql_ddl_global_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_06(self):
INTRO_Q = '''
select schema::Global {
required, cardinality, typ := .target.name,
req_comp := contains(.computed_fields, 'required'),
card_comp := contains(.computed_fields, 'cardinality'),
computed := exists .expr,
}
filter .name = 'default::foo';
'''
await self.con.execute('''
create global foo := 10;
''')
await self.assert_query_result(
INTRO_Q,
[{
"computed": True,
"card_comp": True,
"req_comp": True,
"required": True,
"cardinality": "One",
"typ": "default::foo",
}]
)
await self.con.execute('''
drop global foo;
create optional multi global foo := 10;
''')
await self.assert_query_result(
INTRO_Q,
[{
"computed": True,
"card_comp": False,
"req_comp": False,
"required": False,
"cardinality": "Many",
"typ": "default::foo",
}]
)
await self.con.execute('''
alter global foo reset optionality;
''')
await self.assert_query_result(
INTRO_Q,
[{
"computed": True,
"card_comp": False,
"req_comp": True,
"required": True,
"cardinality": "Many",
"typ": "default::foo",
}]
)
await self.con.execute('''
alter global foo {
reset cardinality;
reset expression;
set type str reset to default;
};
''')
await self.assert_query_result(
INTRO_Q,
[{
"computed": False,
"card_comp": False,
"req_comp": False,
"required": False,
"cardinality": "One",
"typ": "std::str",
}]
) | await self.con.execute( | test_edgeql_ddl_global_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_07(self):
await self.con.execute('''
create global foo := <str>Object.id
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly an empty set returned",
):
await self.con.execute("""
alter global foo set required;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly more than one element returned",
):
await self.con.execute("""
alter global foo set single;
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"cannot specify a type and an expression for a global",
):
await self.con.execute("""
alter global foo set type str reset to default;
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"possibly an empty set returned",
):
await self.con.execute( | test_edgeql_ddl_global_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_08(self):
await self.con.execute('''
create global foo -> str;
set global foo := "test";
''')
await self.con.execute('''
alter global foo set type int64 reset to default;
''')
await self.assert_query_result(
r'''select global foo''',
[]
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r"SET TYPE on global must explicitly reset the global's value"
):
await self.con.execute("""
alter global foo set type str;
""")
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"USING casts for SET TYPE on globals are not supported"
):
await self.con.execute("""
alter global foo set type str using ('lol');
""") | )
await self.con.execute( | test_edgeql_ddl_global_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_09(self):
await self.con.execute('''
create type Org;
create global current_org_id -> uuid;
create global current_org := (
select Org filter .id = global current_org_id
);
create type Widget {
create required link org -> Org {
set default := global current_org;
}
};
''')
obj = await self.con.query_single('insert Org')
await self.con.execute(
'''
set global current_org_id := <uuid>$0
''',
obj.id,
)
await self.con.execute('insert Widget')
await self.assert_query_result(
'''
select Widget { org }
''',
[{'org': {'id': obj.id}}],
) | )
obj = await self.con.query_single('insert Org')
await self.con.execute( | test_edgeql_ddl_global_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_10(self):
await self.con.execute('''
create type Org;
create global current_org_id -> uuid;
create global current_org := (
select Org filter .id = global current_org_id
);
create type Widget {
create required link org -> Org {
create rewrite insert using (global current_org)
}
};
''')
obj = await self.con.query_single('insert Org')
await self.con.execute(
'''
set global current_org_id := <uuid>$0
''',
obj.id,
)
await self.con.execute('insert Widget')
await self.assert_query_result(
'''
select Widget { org }
''',
[{'org': {'id': obj.id}}],
) | )
obj = await self.con.query_single('insert Org')
await self.con.execute( | test_edgeql_ddl_global_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_11(self):
# Just like 9, but with a shape on current_org
await self.con.execute('''
create type Org;
create global current_org_id -> uuid;
create global current_org := (
select Org { * } filter .id = global current_org_id
);
create type Widget {
create required link org -> Org {
set default := global current_org;
}
};
''')
obj = await self.con.query_single('insert Org')
await self.con.execute(
'''
set global current_org_id := <uuid>$0
''',
obj.id,
)
await self.con.execute('insert Widget')
await self.assert_query_result(
'''
select Widget { org }
''',
[{'org': {'id': obj.id}}],
) | )
obj = await self.con.query_single('insert Org')
await self.con.execute( | test_edgeql_ddl_global_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_global_default(self):
await self.con.execute('''
create global foo -> str;
create type Foo;
''')
# Should work; no data in the table to cause trouble
await self.con.execute('''
alter type Foo { create required property name -> str {
set default := (global foo);
} }
''')
await self.con.execute('''
set global foo := "test";
insert Foo;
reset global foo;
''')
await self.assert_query_result(
'''
select Foo { name }
''',
[{'name': "test"}],
)
# Should fail because there is data
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required property"
):
await self.con.execute('''
alter type Foo { create required property name2 -> str {
set default := (global foo);
} }
''')
await self.con.execute('''
alter global foo set default := "!";
create function get_foo() -> optional str using (global foo);
''')
# Try it again now that there is a default
await self.con.execute('''
alter type Foo { create required property name2 -> str {
set default := (global foo);
} };
alter type Foo { create required property name3 -> str {
set default := (get_foo());
} };
''')
await self.assert_query_result(
'''
select Foo { name, name2, name3 }
''',
[{'name': "test", 'name2': "!", 'name3': "!"}],
) | )
# Should work; no data in the table to cause trouble
await self.con.execute( | test_edgeql_ddl_global_default | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_property_computable_01(self):
await self.con.execute('''\
CREATE TYPE CompProp;
ALTER TYPE CompProp {
CREATE PROPERTY prop := 'I am a computable';
};
INSERT CompProp;
''')
await self.assert_query_result(
r'''
SELECT CompProp {
prop
};
''',
[{
'prop': 'I am a computable',
}],
)
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
properties: {
name,
target: {
name
}
} FILTER .name = 'prop'
}
FILTER
.name = 'default::CompProp';
''',
[{
'properties': [{
'name': 'prop',
'target': {
'name': 'std::str'
}
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_property_computable_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_property_computable_02(self):
await self.con.execute('''\
CREATE TYPE CompProp {
CREATE PROPERTY prop := 'I am a computable';
};
INSERT CompProp;
''')
await self.assert_query_result(
r'''
SELECT CompProp {
prop
};
''',
[{
'prop': 'I am a computable',
}],
)
await self.con.execute('''\
ALTER TYPE CompProp {
ALTER PROPERTY prop {
RESET EXPRESSION;
};
};
''')
await self.assert_query_result(
r'''
SELECT CompProp {
prop
};
''',
[{
'prop': None,
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_property_computable_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_property_computable_03(self):
await self.con.execute(r'''
CREATE TYPE Foo {
CREATE PROPERTY bar -> str;
};
''')
await self.con.execute(r'''
ALTER TYPE Foo { ALTER PROPERTY bar { USING (1) } };
''')
await self.con.execute(r'''
ALTER TYPE Foo { ALTER PROPERTY bar { USING ("1") } };
''') | )
await self.con.execute(r | test_edgeql_ddl_property_computable_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_computable_01(self):
await self.con.execute('''\
CREATE TYPE LinkTarget;
CREATE TYPE CompLink {
CREATE MULTI LINK l := LinkTarget;
};
INSERT LinkTarget;
INSERT CompLink;
''')
await self.assert_query_result(
r'''
SELECT CompLink {
l: {
id
}
};
''',
[{
'l': [{
'id': uuid.UUID
}],
}],
)
await self.con.execute('''\
ALTER TYPE CompLink {
ALTER LINK l {
RESET EXPRESSION;
};
};
''')
await self.assert_query_result(
r'''
SELECT CompLink {
l: {
id
}
};
''',
[{
'l': [],
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_link_computable_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_computable_02(self):
await self.con.execute('''
CREATE TYPE LinkTarget;
''')
# TODO We want to actually support this, but until then we should
# have a decent error.
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"including a shape on schema-defined computed links "
r"is not yet supported"
):
await self.con.execute("""
CREATE TYPE X { CREATE LINK x := LinkTarget { z := 1 } };
""") | )
# TODO We want to actually support this, but until then we should
# have a decent error.
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"including a shape on schema-defined computed links "
r"is not yet supported"
):
await self.con.execute( | test_edgeql_ddl_link_computable_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_01(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION attr1;
CREATE SCALAR TYPE TestAttrType1 EXTENDING std::str {
CREATE ANNOTATION attr1 := 'aaaa';
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
annotations: {
name,
@value,
}
}
FILTER
.name = 'default::TestAttrType1';
''',
[{"annotations": [{"name": "default::attr1", "@value": "aaaa"}]}]
)
await self.migrate("""
abstract annotation attr2;
scalar type TestAttrType1 extending std::str {
annotation attr2 := 'aaaa';
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ScalarType {
annotations: {
name,
@value,
}
}
FILTER
.name = 'default::TestAttrType1';
''',
[{"annotations": [{"name": "default::attr2", "@value": "aaaa"}]}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_02(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION attr1;
CREATE TYPE TestAttrType2 {
CREATE ANNOTATION attr1 := 'aaaa';
};
""")
await self.migrate("""
abstract annotation attr2;
type TestAttrType2 {
annotation attr2 := 'aaaa';
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
@value,
} FILTER .name = 'default::attr2'
}
FILTER
.name = 'default::TestAttrType2';
''',
[{"annotations": [{"name": "default::attr2", "@value": "aaaa"}]}]
) | )
await self.migrate( | test_edgeql_ddl_annotation_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_03(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION noninh;
CREATE ABSTRACT INHERITABLE ANNOTATION inh;
CREATE TYPE TestAttr1 {
CREATE ANNOTATION noninh := 'no inherit';
CREATE ANNOTATION inh := 'inherit me';
};
CREATE TYPE TestAttr2 EXTENDING TestAttr1;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
inheritable,
@value,
}
FILTER .name LIKE 'default::%'
ORDER BY .name
}
FILTER
.name LIKE 'default::TestAttr%'
ORDER BY
.name;
''',
[{
"annotations": [{
"name": "default::inh",
"inheritable": True,
"@value": "inherit me",
}, {
"name": "default::noninh",
"@value": "no inherit",
}]
}, {
"annotations": [{
"name": "default::inh",
"inheritable": True,
"@value": "inherit me",
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_04(self):
await self.con.execute('''
CREATE TYPE BaseAnno4;
CREATE TYPE DerivedAnno4 EXTENDING BaseAnno4;
CREATE ABSTRACT ANNOTATION noninh_anno;
CREATE ABSTRACT INHERITABLE ANNOTATION inh_anno;
ALTER TYPE BaseAnno4
CREATE ANNOTATION noninh_anno := '1';
ALTER TYPE BaseAnno4
CREATE ANNOTATION inh_anno := '2';
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
inheritable,
@value,
}
FILTER .name LIKE 'default::%_anno'
ORDER BY .name
}
FILTER
.name = 'default::DerivedAnno4'
ORDER BY
.name;
''',
[{
"annotations": [{
"name": "default::inh_anno",
"inheritable": True,
"@value": "2",
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_05(self):
await self.con.execute(r'''
CREATE TYPE BaseAnno05 {
CREATE PROPERTY name -> str;
CREATE INDEX ON (.name) {
CREATE ANNOTATION title := 'name index'
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno05';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": [{
"name": "std::title",
"@value": "name index",
}]
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_06(self):
await self.con.execute(r'''
CREATE TYPE BaseAnno06 {
CREATE PROPERTY name -> str;
CREATE INDEX ON (.name);
};
''')
await self.con.execute(r'''
ALTER TYPE BaseAnno06 {
ALTER INDEX ON (.name) {
CREATE ANNOTATION title := 'name index'
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno06';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": [{
"name": "std::title",
"@value": "name index",
}]
}]
}]
)
await self.con.execute(r'''
ALTER TYPE BaseAnno06 {
ALTER INDEX ON (.name) {
DROP ANNOTATION title;
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno06';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": []
}]
}]
) | )
await self.con.execute(r | test_edgeql_ddl_annotation_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_07(self):
# Create index annotation using DDL, then drop annotation using SDL.
await self.con.execute(r'''
CREATE TYPE BaseAnno07 {
CREATE PROPERTY name -> str;
CREATE INDEX ON (.name) {
CREATE ANNOTATION title := 'name index'
}
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno07';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": [{
"name": "std::title",
"@value": "name index",
}]
}]
}]
)
await self.migrate(r'''
type BaseAnno07 {
property name -> str;
index ON (.name);
}
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno07';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": []
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_08(self):
# Create index using DDL, then add annotation to it using SDL.
await self.con.execute(r'''
CREATE TYPE BaseAnno08 {
CREATE PROPERTY name -> str;
CREATE INDEX ON (.name);
};
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno08';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": []
}]
}]
)
await self.migrate(r'''
type BaseAnno08 {
property name -> str;
index ON (.name) {
annotation title := 'name index';
}
}
''')
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
indexes: {
expr,
annotations: {
name,
@value,
}
}
}
FILTER
.name = 'default::BaseAnno08';
''',
[{
"indexes": [{
"expr": ".name",
"annotations": [{
"name": "std::title",
"@value": "name index",
}]
}]
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_09(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION anno09;
CREATE TYPE TestTypeAnno09 {
CREATE ANNOTATION anno09 := 'A';
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
@value,
} FILTER .name = 'default::anno09'
}
FILTER
.name = 'default::TestTypeAnno09';
''',
[{"annotations": [{"name": "default::anno09", "@value": "A"}]}]
)
# Alter the annotation.
await self.con.execute("""
ALTER TYPE TestTypeAnno09 {
ALTER ANNOTATION anno09 := 'B';
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
@value,
} FILTER .name = 'default::anno09'
}
FILTER
.name = 'default::TestTypeAnno09';
''',
[{"annotations": [{"name": "default::anno09", "@value": "B"}]}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_10(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION anno10;
CREATE ABSTRACT INHERITABLE ANNOTATION anno10_inh;
CREATE TYPE TestTypeAnno10
{
CREATE ANNOTATION anno10 := 'A';
CREATE ANNOTATION anno10_inh := 'A';
};
CREATE TYPE TestSubTypeAnno10
EXTENDING TestTypeAnno10
{
CREATE ANNOTATION anno10 := 'B';
ALTER ANNOTATION anno10_inh := 'B';
}
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
@value,
}
FILTER .name LIKE 'default::anno10%'
ORDER BY .name
}
FILTER
.name LIKE 'default::%Anno10'
ORDER BY
.name
''',
[
{
"annotations": [
{"name": "default::anno10", "@value": "B"},
{"name": "default::anno10_inh", "@value": "B"},
]
},
{
"annotations": [
{"name": "default::anno10", "@value": "A"},
{"name": "default::anno10_inh", "@value": "A"},
]
},
]
)
# Drop the non-inherited annotation from subtype.
await self.con.execute("""
ALTER TYPE TestSubTypeAnno10 {
DROP ANNOTATION anno10;
};
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT ObjectType {
annotations: {
name,
@value,
} FILTER .name LIKE 'default::anno10%'
}
FILTER
.name = 'default::TestSubTypeAnno10';
''',
[{"annotations": [{"name": "default::anno10_inh", "@value": "B"}]}]
)
with self.assertRaisesRegex(
edgedb.SchemaError,
"cannot drop inherited annotation 'default::anno10_inh'",
):
await self.con.execute("""
ALTER TYPE TestSubTypeAnno10 {
DROP ANNOTATION anno10_inh;
};
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_10 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_11(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION anno11;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Annotation {
name,
}
FILTER
.name LIKE 'default::anno11%';
''',
[{"name": "default::anno11"}]
)
await self.con.execute("""
ALTER ABSTRACT ANNOTATION anno11
RENAME TO anno11_new_name;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Annotation {
name,
}
FILTER
.name LIKE 'default::anno11%';
''',
[{"name": "default::anno11_new_name"}]
)
await self.con.execute("""
CREATE MODULE foo;
ALTER ABSTRACT ANNOTATION anno11_new_name
RENAME TO foo::anno11_new_name;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Annotation {
name,
}
FILTER
.name LIKE 'foo::anno11%';
''',
[{"name": "foo::anno11_new_name"}]
)
await self.con.execute("""
DROP ABSTRACT ANNOTATION foo::anno11_new_name;
""")
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT Annotation {
name,
}
FILTER
.name LIKE 'foo::anno11%';
''',
[]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_annotation_11 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_13(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION anno13;
""")
with self.assertRaisesRegex(
edgedb.UnknownModuleError,
"module 'bogus' is not in this schema",
):
await self.con.execute("""
ALTER ABSTRACT ANNOTATION anno13 RENAME TO bogus::anno13;
""") | )
with self.assertRaisesRegex(
edgedb.UnknownModuleError,
"module 'bogus' is not in this schema",
):
await self.con.execute( | test_edgeql_ddl_annotation_13 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_14(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION anno;
CREATE TYPE Foo {
CREATE ANNOTATION anno := "test";
};
""")
await self.con.execute("""
ALTER ABSTRACT ANNOTATION anno
RENAME TO anno_new_name;
""")
await self.assert_query_result(
"DESCRIBE MODULE default as sdl",
["""
abstract annotation default::anno_new_name;
type default::Foo {
annotation default::anno_new_name := 'test';
};
""".strip()]
)
await self.con.execute("""
DROP TYPE Foo;
""") | )
await self.con.execute( | test_edgeql_ddl_annotation_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_15(self):
await self.con.execute("""
CREATE ABSTRACT INHERITABLE ANNOTATION anno;
CREATE TYPE Foo {
CREATE PROPERTY prop -> str {
CREATE ANNOTATION anno := "parent";
};
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY prop {
ALTER ANNOTATION anno := "child";
}
};
""")
qry = '''
WITH MODULE schema
SELECT Property {
obj := .source.name,
annotations: {name, @value, @owned}
ORDER BY .name
}
FILTER
.name = 'prop'
ORDER BY
(.obj, .name);
'''
await self.assert_query_result(
qry,
[
{
"annotations": [
{"@value": "child", "@owned": True,
"name": "default::anno"}
],
"obj": "default::Bar"
},
{
"annotations": [
{"@value": "parent", "@owned": True,
"name": "default::anno"}
],
"obj": "default::Foo"
}
]
)
await self.con.execute("""
ALTER TYPE Bar {
ALTER PROPERTY prop {
ALTER ANNOTATION anno DROP OWNED;
}
};
""")
await self.assert_query_result(
qry,
[
{
"annotations": [
{"@value": "parent", "@owned": False,
"name": "default::anno"}
],
"obj": "default::Bar"
},
{
"annotations": [
{"@value": "parent", "@owned": True,
"name": "default::anno"}
],
"obj": "default::Foo"
}
]
) | )
qry = | test_edgeql_ddl_annotation_15 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_16(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION attr1;
""")
with self.assertRaisesRegex(
edgedb.InvalidValueError,
r"annotation values must be 'std::str', "
r"got scalar type 'std::int64'"):
await self.con.execute("""
CREATE SCALAR TYPE TestAttrType1 EXTENDING std::str {
CREATE ANNOTATION attr1 := 10;
};
""") | )
with self.assertRaisesRegex(
edgedb.InvalidValueError,
r"annotation values must be 'std::str', "
r"got scalar type 'std::int64'"):
await self.con.execute( | test_edgeql_ddl_annotation_16 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_17(self):
await self.con.execute("""
CREATE ABSTRACT ANNOTATION attr1;
CREATE SCALAR TYPE TestAttrType1 EXTENDING std::str {
CREATE ANNOTATION attr1 := '10';
};
""")
with self.assertRaisesRegex(
edgedb.InvalidValueError,
r"annotation values must be 'std::str', "
r"got scalar type 'std::int64'"):
await self.con.execute("""
ALTER SCALAR TYPE TestAttrType1 {
ALTER ANNOTATION attr1 := 10;
};
""") | )
with self.assertRaisesRegex(
edgedb.InvalidValueError,
r"annotation values must be 'std::str', "
r"got scalar type 'std::int64'"):
await self.con.execute( | test_edgeql_ddl_annotation_17 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_annotation_18(self):
# An annotation on an annotation!
await self.con.execute("""
CREATE ABSTRACT ANNOTATION ann {
CREATE ANNOTATION description := "foo";
};
""")
qry = '''
WITH MODULE schema
SELECT Annotation {
annotations: {name, @value}
}
FILTER .name = 'default::ann'
'''
await self.assert_query_result(
qry,
[{"annotations": [{"@value": "foo", "name": "std::description"}]}]
)
await self.con.execute("""
ALTER ABSTRACT ANNOTATION ann {
ALTER ANNOTATION description := "bar";
};
""")
await self.assert_query_result(
qry,
[{"annotations": [{"@value": "bar", "name": "std::description"}]}]
)
await self.con.execute("""
ALTER ABSTRACT ANNOTATION ann {
DROP ANNOTATION description;
};
""")
await self.assert_query_result(
qry,
[{"annotations": []}]
) | )
qry = | test_edgeql_ddl_annotation_18 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_extending_03(self):
# Check that ancestors are recomputed properly on rebase.
await self.con.execute(r"""
CREATE TYPE ExtA3;
CREATE TYPE ExtB3 EXTENDING ExtA3;
CREATE TYPE ExtC3 EXTENDING ExtB3;
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
ancestors: {
name
} ORDER BY @index
}
FILTER .name = 'default::ExtC3'
""",
[{
'ancestors': [{
'name': 'default::ExtB3',
}, {
'name': 'default::ExtA3',
}, {
'name': 'std::Object',
}, {
'name': 'std::BaseObject',
}],
}]
)
await self.con.execute(r"""
ALTER TYPE ExtB3 DROP EXTENDING ExtA3;
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
ancestors: {
name
} ORDER BY @index
}
FILTER .name = 'default::ExtC3'
""",
[{
'ancestors': [{
'name': 'default::ExtB3',
}, {
'name': 'std::Object',
}, {
'name': 'std::BaseObject',
}],
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_extending_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.