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
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
async def test_edgeql_ddl_errors_02(self):
await self.con.execute('''
CREATE TYPE Err2 {
CREATE REQUIRED PROPERTY foo -> str;
};
ALTER TYPE Err2
CREATE REQUIRED LINK bar -> Err2;
''')
async with self._run_and_rollback():
with self.assertRaisesRegex(
edgedb.errors.InvalidReferenceError,
"link 'foo' does not exist"):
await self.con.execute('''
ALTER TYPE Err2
ALTER LINK foo
DROP PROPERTY spam;
''') | )
async with self._run_and_rollback():
with self.assertRaisesRegex(
edgedb.errors.InvalidReferenceError,
"link 'foo' does not exist"):
await self.con.execute( | test_edgeql_ddl_errors_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_errors_03(self):
async with self._run_and_rollback():
with self.assertRaisesRegex(
edgedb.errors.InvalidReferenceError,
"function 'default::foo___1' does not exist"):
await self.con.execute('''
ALTER FUNCTION foo___1(a: int64)
SET volatility := 'Stable';
''')
async with self._run_and_rollback():
with self.assertRaisesRegex(
edgedb.errors.InvalidReferenceError,
"function 'default::foo___1' does not exist"):
await self.con.execute('''
DROP FUNCTION foo___1(a: int64);
''') | )
async with self._run_and_rollback():
with self.assertRaisesRegex(
edgedb.errors.InvalidReferenceError,
"function 'default::foo___1' does not exist"):
await self.con.execute( | test_edgeql_ddl_errors_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_create_migration_05(self):
await self.con.execute('''
create type X { create property x -> str; };
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidReferenceError,
"property 'x' does not"):
await self.con.execute('''
CREATE MIGRATION
{
alter type default::X {
alter property x rename to y;
};
alter type default::X {
alter property x create constraint exclusive;
};
};
''') | )
async with self.assertRaisesRegexTx(
edgedb.InvalidReferenceError,
"property 'x' does not"):
await self.con.execute( | test_edgeql_ddl_create_migration_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 _simple_rename_ref_test(
self,
ddl,
cleanup=None,
*,
rename_type,
rename_prop,
rename_module,
type_extra=0,
prop_extra=0,
type_refs=1,
prop_refs=1,
):
"""Driver for simple rename tests for objects with expr references.
Supports renaming a type, a property, or both. By default,
each is expected to be named once in the referencing object.
"""
await self.con.execute(f"""
CREATE TYPE Note {{
CREATE PROPERTY note -> str;
}};
{ddl.lstrip()}
""")
type_rename = "RENAME TO Remark;" if rename_type else ""
prop_rename = (
"ALTER PROPERTY note RENAME TO remark;" if rename_prop else "")
await self.con.execute(f"""
ALTER TYPE Note {{
{type_rename.lstrip()}
{prop_rename.lstrip()}
}}
""")
if rename_module:
await self.con.execute(f"""
CREATE MODULE foo;
ALTER TYPE Note RENAME TO foo::Note;
""")
else:
res = await self.con.query_single("""
DESCRIBE MODULE default
""")
total_type = 1 + type_refs
num_type_orig = 0 if rename_type else total_type
self.assertEqual(res.count("Note"), num_type_orig + type_extra)
self.assertEqual(res.count("Remark"), total_type - num_type_orig)
total_prop = 1 + prop_refs
num_prop_orig = 0 if rename_prop else total_prop
self.assertEqual(res.count("note"), num_prop_orig + type_extra)
self.assertEqual(res.count("remark"), total_prop - num_prop_orig)
if cleanup:
if rename_prop:
cleanup = cleanup.replace("note", "remark")
if rename_type:
cleanup = cleanup.replace("Note", "Remark")
if rename_module:
cleanup = cleanup.replace("default", "foo")
await self.con.execute(f"""
{cleanup.lstrip()}
""") | Driver for simple rename tests for objects with expr references.
Supports renaming a type, a property, or both. By default,
each is expected to be named once in the referencing object. | _simple_rename_ref_test | 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 _simple_rename_ref_tests(self, ddl, cleanup=None, **kwargs):
"""Do the three interesting invocations of _simple_rename_ref_test"""
async with self._run_and_rollback():
await self._simple_rename_ref_test(
ddl, cleanup,
rename_type=False, rename_prop=True, rename_module=False,
**kwargs)
async with self._run_and_rollback():
await self._simple_rename_ref_test(
ddl, cleanup,
rename_type=True, rename_prop=False, rename_module=False,
**kwargs)
async with self._run_and_rollback():
await self._simple_rename_ref_test(
ddl, cleanup,
rename_type=True, rename_prop=True, rename_module=False,
**kwargs)
async with self._run_and_rollback():
await self._simple_rename_ref_test(
ddl, cleanup,
rename_type=False, rename_prop=False, rename_module=True,
**kwargs) | Do the three interesting invocations of _simple_rename_ref_test | _simple_rename_ref_tests | 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_rename_ref_rewrites_01(self):
await self._simple_rename_ref_tests(
"""
alter type Note create property rtest -> str {
create rewrite update using (.note);
};
""",
"""
alter type default::Note drop property rtest;
""",
type_refs=0,
) | alter type Note create property rtest -> str {
create rewrite update using (.note);
};
""", | test_edgeql_ddl_rename_ref_rewrites_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_rename_ref_triggers_01(self):
await self._simple_rename_ref_tests(
"""
alter type Note {
create trigger log_new after insert, update for each
do (__new__.note);
};
""",
"""
alter type default::Note drop trigger log_new;
""",
type_refs=0,
) | alter type Note {
create trigger log_new after insert, update for each
do (__new__.note);
};
""", | test_edgeql_ddl_rename_ref_triggers_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_rename_ref_prop_alias_01(self):
await self._simple_rename_ref_tests(
"""
alter type Note {
create property lol := (.note);
};
""",
"""
alter type default::Note drop property lol;
""",
type_refs=0,
) | alter type Note {
create property lol := (.note);
};
""", | test_edgeql_ddl_rename_ref_prop_alias_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_collection_cleanup_01(self):
count_query = "SELECT count(schema::Tuple);"
orig_count = await self.con.query_single(count_query)
await self.con.execute(r"""
CREATE SCALAR TYPE a extending str;
CREATE SCALAR TYPE b extending str;
CREATE SCALAR TYPE c extending str;
CREATE TYPE TestTuples {
CREATE PROPERTY x -> tuple<a>;
CREATE PROPERTY y -> tuple<b>;
};
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2,
)
await self.con.execute(r"""
ALTER TYPE TestTuples {
DROP PROPERTY x;
};
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 1,
)
await self.con.execute(r"""
ALTER TYPE TestTuples {
ALTER PROPERTY y {
SET TYPE tuple<c> USING (
<tuple<c>><tuple<str>>.y);
}
};
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 1,
)
await self.con.execute(r"""
DROP TYPE TestTuples;
""")
self.assertEqual(await self.con.query_single(count_query), orig_count) | )
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2,
)
await self.con.execute(r | test_edgeql_ddl_collection_cleanup_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_collection_cleanup_02(self):
count_query = "SELECT count(schema::CollectionType);"
orig_count = await self.con.query_single(count_query)
await self.con.execute(r"""
CREATE SCALAR TYPE a extending str;
CREATE SCALAR TYPE b extending str;
CREATE SCALAR TYPE c extending str;
CREATE TYPE TestArrays {
CREATE PROPERTY x -> array<tuple<a, b>>;
};
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
await self.con.execute(r"""
DROP TYPE TestArrays;
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3,
) | )
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
await self.con.execute(r | test_edgeql_ddl_collection_cleanup_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_collection_cleanup_04(self):
count_query = "SELECT count(schema::CollectionType);"
orig_count = await self.con.query_single(count_query)
await self.con.execute(r"""
CREATE SCALAR TYPE a extending str;
CREATE SCALAR TYPE b extending str;
CREATE SCALAR TYPE c extending str;
CREATE TYPE Foo {
CREATE PROPERTY a -> a;
CREATE PROPERTY b -> b;
CREATE PROPERTY c -> c;
};
CREATE ALIAS Bar := Foo { thing := (.a, .b) };
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 1,
)
await self.con.execute(r"""
ALTER ALIAS Bar USING (Foo { thing := (.a, .b, .c) });
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 1,
)
await self.con.execute(r"""
ALTER ALIAS Bar USING (Foo { thing := (.a, (.b, .c)) });
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
await self.con.execute(r"""
ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c) });
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
await self.con.execute(r"""
ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c, "foo") });
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
# Make a change that doesn't change the types
await self.con.execute(r"""
ALTER ALIAS Bar USING (Foo { thing := ((.a, .b), .c, "bar") });
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 2,
)
await self.con.execute(r"""
DROP ALIAS Bar;
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3,
) | )
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 3 + 1,
)
await self.con.execute(r | test_edgeql_ddl_collection_cleanup_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_collection_cleanup_05(self):
count_query = "SELECT count(schema::CollectionType);"
orig_count = await self.con.query_single(count_query)
await self.con.execute(r"""
CREATE SCALAR TYPE a extending str;
CREATE SCALAR TYPE b extending str;
CREATE ALIAS Bar := (<a>"", <b>"");
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2 + 2, # one for tuple<str, str>
# one for TupleExprAlias,
# two for implicit array<a> and array<b>
)
await self.con.execute(r"""
ALTER ALIAS Bar USING ((<b>"", <a>""));
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2 + 2,
)
await self.con.execute(r"""
DROP ALIAS Bar;
""")
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2,
) | )
self.assertEqual(
await self.con.query_single(count_query),
orig_count + 2 + 2, # one for tuple<str, str>
# one for TupleExprAlias,
# two for implicit array<a> and array<b>
)
await self.con.execute(r | test_edgeql_ddl_collection_cleanup_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_drop_field_03(self):
await self.con.execute(r"""
CREATE ABSTRACT CONSTRAINT bogus {
USING (false);
SET errmessage := "never!";
};
CREATE TYPE Foo {
CREATE CONSTRAINT bogus on (true);
};
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'never!',
):
await self.con.execute(r"""
INSERT Foo;
""")
await self.con.execute(r"""
ALTER ABSTRACT CONSTRAINT bogus
RESET errmessage;
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'invalid Foo',
):
await self.con.execute(r"""
INSERT Foo;
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'never!',
):
await self.con.execute(r | test_edgeql_ddl_drop_field_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_adjust_computed_11(self):
await self.con.execute(r'''
CREATE TYPE default::Foo;
CREATE TYPE default::Bar {
CREATE LINK foos := (default::Foo);
};
''')
# it's annoying that we need the using on the RESET CARDINALITY;
# maybe we should be able to know it isn't needed
await self.con.execute(r'''
ALTER TYPE default::Bar {
ALTER LINK foos {
RESET EXPRESSION;
RESET CARDINALITY using (<Foo>{});
RESET OPTIONALITY;
SET TYPE default::Foo;
};
}
''') | )
# it's annoying that we need the using on the RESET CARDINALITY;
# maybe we should be able to know it isn't needed
await self.con.execute(r | test_edgeql_ddl_adjust_computed_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_link_policy_12(self):
await self.con.execute("""
create type Tgt;
create type Foo {
create link tgt -> Tgt {
on target delete allow;
}
};
create type Bar extending Foo {
alter link tgt {
on target delete restrict;
}
};
""")
# Make sure we can still delete on Foo
await self.con.execute("""
insert Foo { tgt := (insert Tgt) };
delete Tgt;
""")
await self.con.execute("""
insert Bar { tgt := (insert Tgt) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'prohibited by link target policy',
):
await self.con.execute("""
delete Tgt;
""")
await self.con.execute("""
alter type Bar {
alter link tgt {
reset on target delete;
}
};
""")
await self.con.execute("""
delete Tgt
""")
await self.assert_query_result(
r"""
select schema::Link {name, on_target_delete, source: {name}}
filter .name = 'tgt';
""",
tb.bag([
{
"name": "tgt",
"on_target_delete": "Allow",
"source": {"name": "default::Foo"}
},
{
"name": "tgt",
"on_target_delete": "Allow",
"source": {"name": "default::Bar"}
}
]),
) | )
# Make sure we can still delete on Foo
await self.con.execute( | test_edgeql_ddl_link_policy_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_no_volatile_computable_01(self):
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute("""
CREATE TYPE Foo {
CREATE PROPERTY foo := random();
}
""")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute("""
CREATE TYPE Foo {
CREATE PROPERTY foo := (SELECT {
asdf := random()
}).asdf
}
""")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute("""
CREATE TYPE Noob {
CREATE MULTI LINK friends -> Noob;
CREATE LINK best_friends := (
SELECT .friends FILTER random() > 0.5
);
}
""")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute("""
CREATE TYPE Noob {
CREATE LINK noob -> Noob {
CREATE PROPERTY foo := random();
}
}
""")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute("""
CREATE ALIAS Asdf := Object { foo := random() };
""") | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"volatile functions are not permitted in schema-defined "
"computed expressions",
):
await self.con.execute( | test_edgeql_ddl_no_volatile_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_new_required_pointer_01(self):
await self.con.execute(r"""
CREATE TYPE Foo;
INSERT Foo;
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required property 'name' of object type "
"'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo CREATE REQUIRED PROPERTY name -> str;
""") | )
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required property 'name' of object type "
"'default::Foo'"
):
await self.con.execute( | test_edgeql_ddl_new_required_pointer_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_new_required_multi_pointer_02(self):
await self.con.execute(r"""
CREATE TYPE Foo;
INSERT Foo;
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required link 'link' of object type "
"'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo CREATE REQUIRED MULTI LINK link -> Object;
""") | )
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required link 'link' of object type "
"'default::Foo'"
):
await self.con.execute( | test_edgeql_ddl_new_required_multi_pointer_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_recursive_func(self):
await self.con.execute(r'''
CREATE TYPE SomeThing {
CREATE LINK child -> SomeThing;
}
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"function 'get_all_children_ordered' does not exist"
):
await self.con.execute(r'''
CREATE FUNCTION get_all_children_ordered(parent: SomeThing)
-> SET OF SomeThing Using (
SELECT SomeThing UNION get_all_children_ordered(parent))
''')
await self.con.execute(r'''
CREATE FUNCTION get_all_children_ordered(parent: SomeThing)
-> SET OF SomeThing Using (
SELECT SomeThing
)
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r"function 'default::get_all_children_ordered"
r"\(parent: default::SomeThing\)' is defined recursively"
):
await self.con.execute(r'''
ALTER FUNCTION get_all_children_ordered(parent: SomeThing)
USING (
SELECT parent.child
UNION get_all_children_ordered(parent)
);
''') | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"function 'get_all_children_ordered' does not exist"
):
await self.con.execute(r | test_edgeql_ddl_recursive_func | 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_duplicates_01(self):
await self.con.execute(r"""
CREATE TYPE Foo;
""")
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"object type 'default::Foo' already exists"):
await self.con.execute(r"""
CREATE TYPE Foo;
""") | )
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"object type 'default::Foo' already exists"):
await self.con.execute(r | test_edgeql_ddl_duplicates_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_duplicates_02(self):
await self.con.execute(r"""
CREATE TYPE Foo {
CREATE PROPERTY foo -> str;
}
""")
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"property 'foo' of "
r"object type 'default::Foo' already exists"):
await self.con.execute(r"""
ALTER TYPE Foo {
CREATE PROPERTY foo -> str;
}
""") | )
with self.assertRaisesRegex(
edgedb.errors.SchemaError,
r"property 'foo' of "
r"object type 'default::Foo' already exists"):
await self.con.execute(r | test_edgeql_ddl_duplicates_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_alias_in_computable_01(self):
await self.con.execute(r"""
CREATE ALIAS Alias := {0, 1, 2, 3};
""")
# We don't want to prohibit this forever, but we need to for now.
async with self.assertRaisesRegexTx(
edgedb.errors.UnsupportedFeatureError,
r"referring to alias 'default::Alias' from computed property"):
await self.con.execute(r"""
CREATE TYPE Foo {
CREATE PROPERTY bar := Alias;
};
""")
async with self.assertRaisesRegexTx(
edgedb.errors.UnsupportedFeatureError,
r"referring to alias 'default::Alias' from computed property"):
await self.con.execute(r"""
CREATE TYPE Foo {
CREATE PROPERTY bar := {Alias, Alias};
};
""") | )
# We don't want to prohibit this forever, but we need to for now.
async with self.assertRaisesRegexTx(
edgedb.errors.UnsupportedFeatureError,
r"referring to alias 'default::Alias' from computed property"):
await self.con.execute(r | test_edgeql_ddl_alias_in_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_switch_link_target(self):
await self.con.execute(r"""
create type Foo;
create type Bar;
create type Ptr { create link p -> Foo; };
alter type Ptr { alter link p set type Bar using (<Bar>{}); };
insert Ptr { p := (insert Bar) };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"prohibited by link target policy",
):
await self.con.execute("""
delete Bar;
""")
await self.con.execute(r"""
drop type Ptr;
""")
await self.con.execute(r"""
insert Foo;
delete Foo;
""") | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"prohibited by link target policy",
):
await self.con.execute( | test_edgeql_ddl_switch_link_target | 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_set_abstract_bogus_01(self):
await self.con.execute(r"""
create type Foo;
insert Foo;
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r"may not make non-empty object type 'default::Foo' abstract"):
await self.con.execute(r"""
alter type Foo set abstract;
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r"may not make non-empty object type 'default::Foo' abstract"):
await self.con.execute(r | test_edgeql_ddl_set_abstract_bogus_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_no_shapes_in_using(self):
await self.con.execute(r"""
create type Foo;
create type Bar extending Foo;
create type Baz {
create multi link foo -> Foo;
};
""")
q = 'select Bar { x := "oops" } limit 1'
alters = [
f'set required using ({q})',
f'set single using ({q})',
f'set default := ({q})',
f'set type Bar using ({q})',
]
for alter in alters:
async with self.assertRaisesRegexTx(
(edgedb.SchemaError, edgedb.SchemaDefinitionError),
r"may not include a shape"):
await self.con.execute(fr"""
alter type Baz {{
alter link foo {{
{alter}
}}
}};
""") | )
q = 'select Bar { x := "oops" } limit 1'
alters = [
f'set required using ({q})',
f'set single using ({q})',
f'set default := ({q})',
f'set type Bar using ({q})',
]
for alter in alters:
async with self.assertRaisesRegexTx(
(edgedb.SchemaError, edgedb.SchemaDefinitionError),
r"may not include a shape"):
await self.con.execute(fr | test_edgeql_ddl_no_shapes_in_using | 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_computed_intersection_lprop_01(self):
await self.con.execute(r"""
create type Pointer;
create type Property extending Pointer;
create type Link extending Pointer;
create type ObjectType {
create multi link pointers -> Pointer {
create property owned -> bool;
};
create link links := .pointers[is Link];
};
""")
await self.con.query(r"""
select ObjectType {links: {@owned}};
""") | )
await self.con.query(r | test_edgeql_ddl_computed_intersection_lprop_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_no_tx_mig_error_01(self):
await self.con.execute('''
create type Mig01;
insert Mig01;
''')
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test it standalone
await self.con.query('''
alter type Mig01 create required property n -> int64;
''') | )
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test it standalone
await self.con.query( | test_edgeql_ddl_no_tx_mig_error_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_no_tx_mig_error_02(self):
await self.con.execute('''
create type Mig02;
insert Mig02;
''')
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test it in a script
await self.con.query('''
alter type Mig02 create required property n -> int64;
create type Mig02b;
''') | )
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test it in a script
await self.con.query( | test_edgeql_ddl_no_tx_mig_error_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_no_tx_mig_error_03(self):
await self.con.execute('''
create type Mig03;
''')
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test a non-DDL failure in the script where prop was created
await self.con.query('''
alter type Mig03 create required property n -> int64;
insert Mig03 { n := <int64>{} };
''') | )
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required property 'n'"):
# Test a non-DDL failure in the script where prop was created
await self.con.query( | test_edgeql_ddl_no_tx_mig_error_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_reindex(self):
await self.con.execute('''
create type Tgt;
create type Foo {
create property foo -> str {
create constraint exclusive;
};
create property bar -> str;
create index on (.foo);
create constraint exclusive on ((.foo, .bar));
create link tgt -> Tgt {
create property foo -> str;
};
create link tgts -> Tgt {
create property foo -> str;
};
};
create module test;
create type test::Bar extending Foo;
''')
try:
await self.con.execute('''
administer reindex(Foo)
''')
await self.con.execute('''
administer reindex(Foo.foo)
''')
await self.con.execute('''
administer reindex(Foo.bar)
''')
await self.con.execute('''
administer reindex(Foo.tgt)
''')
await self.con.execute('''
administer reindex(Foo.tgts)
''')
await self.con.execute('''
administer reindex(test::Bar)
''')
await self.con.execute('''
administer reindex(Object)
''')
finally:
await self.con.execute('''
drop type test::Bar;
drop type Foo;
drop type Tgt;
drop module test;
''') | )
try:
await self.con.execute( | test_edgeql_ddl_reindex | 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 _deadlock_tester(self, setup, teardown, modification, query):
"""Deadlock test helper.
Interleave a long running query, some DDL, and a short running query
in a way that has triggered deadlock in the past.
(See #6304.)
"""
cons = []
con1 = self.con
await con1.execute(setup)
try:
for _ in range(2):
con = await self.connect(database=self.con.dbname)
await con.query('select 1')
cons.append(con)
con2, con3 = cons
long_call = asyncio.create_task(con1.query_single(f'''
select (count({query}), sys::_sleep(3));
'''))
await asyncio.sleep(0.5)
ddl = asyncio.create_task(con2.execute(modification))
await asyncio.sleep(0.5)
short_call = con3.query(f'''
select {query}
''')
return await asyncio.gather(long_call, ddl, short_call)
finally:
await self.con.execute(teardown)
for con in cons:
await con.aclose() | Deadlock test helper.
Interleave a long running query, some DDL, and a short running query
in a way that has triggered deadlock in the past.
(See #6304.) | _deadlock_tester | 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_deadlock_01(self):
((cnt, _), _, objs) = await self._deadlock_tester(
setup='''
create type X;
insert X;
''',
teardown='''
drop type X;
''',
modification='''
alter type X create property foo -> str;
''',
query='X',
)
self.assertEqual(cnt, 1)
self.assertEqual(len(objs), 1) | ,
teardown= | test_edgeql_ddl_deadlock_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_single_index(self):
# Test that types only have a single index for id
await self.con.execute('''
create type DDLSingleIndex;
''')
objid = await self.con.query_single('''
select (introspect DDLSingleIndex).id
''')
async with self.with_backend_sql_connection() as scon:
res = await scon.fetch(
f'''
select indexname, tablename, indexdef from pg_indexes
where tablename = $1::text
''',
str(objid),
)
self.assertEqual(
len(res),
1,
f"Too many indexes on .id: {res}",
) | )
objid = await self.con.query_single( | test_edgeql_ddl_single_index | 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_drop_tuple_cache(self):
await self.con.execute('''
create function lol() -> SET OF tuple<str, str> using (('x', 'y'));
''')
# Run many times to wait for the func cache creation
for _ in range(64):
await self.assert_query_result(
'select lol()',
[('x', 'y')]
)
# This drop should succeed, even when the func cache depends on the
# returning tuple type; the cache should be evicted.
await self.con.execute('''
drop function lol();
''') | )
# Run many times to wait for the func cache creation
for _ in range(64):
await self.assert_query_result(
'select lol()',
[('x', 'y')]
)
# This drop should succeed, even when the func cache depends on the
# returning tuple type; the cache should be evicted.
await self.con.execute( | test_edgeql_ddl_function_drop_tuple_cache | 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_rollback_enum_01(self):
await self.con.query("START TRANSACTION")
await self.con.execute('''
CREATE SCALAR TYPE Color
EXTENDING enum<Red, Green, Blue>;
''')
await self.con.query('DECLARE SAVEPOINT t0')
with self.assertRaisesRegex(
edgedb.SchemaError,
'cannot DROP EXTENDING enum'):
await self.con.execute('''
ALTER SCALAR TYPE Color
DROP EXTENDING enum<Red, Green, Blue>;
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
with self.assertRaisesRegex(
edgedb.SchemaError,
"cannot add supertype scalar type 'std::str' to enum type "
"default::Color"):
await self.con.execute('''
ALTER SCALAR TYPE Color EXTENDING str FIRST;
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
with self.assertRaisesRegex(
edgedb.SchemaError,
'cannot add supertype enum<Bad> to enum type default::Color'):
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Bad> LAST;
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
with self.assertRaisesRegex(
edgedb.SchemaError,
'enum default::Color may not have multiple supertypes'):
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Bad>, enum<AlsoBad>;
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
with self.assertRaisesRegex(
edgedb.SchemaError,
'enums cannot contain duplicate values'):
await self.con.execute('''
ALTER SCALAR TYPE Color
EXTENDING enum<Red, Green, Blue, Red>;
''')
# Recover.
await self.con.query('ROLLBACK TO SAVEPOINT t0;')
await self.con.execute(r'''
ALTER SCALAR TYPE Color
EXTENDING enum<Red, Green, Blue, Magic>;
''')
# Commit the changes and before continuing testing.
await self.con.query("COMMIT")
await self.assert_query_result(
r"""
SELECT <Color>'Magic' >
<Color>'Red';
""",
[True],
) | )
await self.con.query('DECLARE SAVEPOINT t0')
with self.assertRaisesRegex(
edgedb.SchemaError,
'cannot DROP EXTENDING enum'):
await self.con.execute( | test_edgeql_ddl_rollback_enum_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_aliases_if_else_02(self):
await self.assert_query_result(
r"""
# working with singletons
SELECT
_ := (
for u in User
select 'ok' IF u.deck_cost < 19 ELSE u.deck.name
)
ORDER BY _;
""",
[
'Bog monster',
'Djinn',
'Dragon',
'Giant eagle',
'Giant turtle',
'Golem',
'Sprite',
'ok',
'ok',
'ok',
],
)
await self.assert_query_result(
r"""
# either result is a set, but the condition is a singleton
SELECT
_ := (
for u in User
select u.deck.element IF u.deck_cost < 19
ELSE u.deck.name
)
ORDER BY _;
""",
[
'Air',
'Air',
'Air',
'Bog monster',
'Djinn',
'Dragon',
'Earth',
'Earth',
'Earth',
'Earth',
'Fire',
'Fire',
'Giant eagle',
'Giant turtle',
'Golem',
'Sprite',
'Water',
'Water',
'Water',
'Water',
'Water',
'Water',
],
) | ,
[
'Bog monster',
'Djinn',
'Dragon',
'Giant eagle',
'Giant turtle',
'Golem',
'Sprite',
'ok',
'ok',
'ok',
],
)
await self.assert_query_result(
r | test_edgeql_aliases_if_else_02 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_if_else_03(self):
res = [
['Air', 'Air', 'Air', 'Earth', 'Earth', 'Fire', 'Fire', 'Water',
'Water'],
['1', '1', '1', '2', '2', '3', '3', '4', '5'],
[False, False, False, True, True],
]
await self.assert_query_result(
r"""
# get the data that this test relies upon in a format
# that's easy to analyze
SELECT _ := User.deck.element
ORDER BY _;
""",
res[0]
)
await self.assert_query_result(
r"""
SELECT _ := <str>User.deck.cost
ORDER BY _;
""",
res[1]
)
await self.assert_query_result(
r"""
SELECT _ := {User.name[0] = 'A', EXISTS User.friends}
ORDER BY _;
""",
res[2]
)
await self.assert_query_result(
r"""
# results and conditions are sets
SELECT _ :=
User.deck.element
# because the elements of {} are treated as SET OF,
# all of the paths in this expression are independent sets
IF {User.name[0] = 'A', EXISTS User.friends} ELSE
<str>User.deck.cost
ORDER BY _;
""",
sorted(res[1] + res[1] + res[1] + res[0] + res[0]),
) | ,
res[0]
)
await self.assert_query_result(
r | test_edgeql_aliases_if_else_03 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_if_else_04(self):
await self.assert_query_result(
r"""
FOR User in User
SELECT
1 IF User.name[0] = 'A' ELSE
10 IF User.name[0] = 'B' ELSE
100 IF User.name[0] = 'C' ELSE
0;
""",
{1, 10, 100, 0},
)
await self.assert_query_result(
r"""
FOR User in User
SELECT (
User.name,
sum((
FOR f in User.friends SELECT
1 IF f.name[0] = 'A' ELSE
10 IF f.name[0] = 'B' ELSE
100 IF f.name[0] = 'C' ELSE
0
)),
) ORDER BY .0;
""",
[['Alice', 110], ['Bob', 0], ['Carol', 0], ['Dave', 10]],
) | ,
{1, 10, 100, 0},
)
await self.assert_query_result(
r | test_edgeql_aliases_if_else_04 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_if_else_05(self):
await self.assert_query_result(
r"""
SELECT (
FOR Card in Card
SELECT
(Card.name, 'yes' IF Card.cost > 4 ELSE 'no')
)
ORDER BY .0;
""",
[
['Bog monster', 'no'],
['Djinn', 'no'],
['Dragon', 'yes'],
['Dwarf', 'no'],
['Giant eagle', 'no'],
['Giant turtle', 'no'],
['Golem', 'no'],
['Imp', 'no'],
['Sprite', 'no'],
],
)
await self.assert_query_result(
r"""
SELECT (
FOR Card in Card
SELECT
(Card.name, 'yes') IF Card.cost > 4 ELSE (Card.name, 'no')
)
ORDER BY .0;
""",
[
['Bog monster', 'no'],
['Djinn', 'no'],
['Dragon', 'yes'],
['Dwarf', 'no'],
['Giant eagle', 'no'],
['Giant turtle', 'no'],
['Golem', 'no'],
['Imp', 'no'],
['Sprite', 'no'],
],
) | ,
[
['Bog monster', 'no'],
['Djinn', 'no'],
['Dragon', 'yes'],
['Dwarf', 'no'],
['Giant eagle', 'no'],
['Giant turtle', 'no'],
['Golem', 'no'],
['Imp', 'no'],
['Sprite', 'no'],
],
)
await self.assert_query_result(
r | test_edgeql_aliases_if_else_05 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_deep_01(self):
# fetch the result we will compare to
res = await self.con.query_json(r"""
SELECT AwardAlias {
winner: {
deck: {
owners
}
}
}
FILTER .name = '1st'
LIMIT 1;
""")
res = json.loads(res)
# fetch the same data via a different alias, that should be
# functionally identical
await self.assert_query_result(
r"""
SELECT AwardAlias2 {
winner: {
deck: {
owners
}
}
}
FILTER .name = '1st';
""",
res
) | )
res = json.loads(res)
# fetch the same data via a different alias, that should be
# functionally identical
await self.assert_query_result(
r | test_edgeql_aliases_deep_01 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_clauses_01(self):
# fetch the result we will compare to
res = await self.con.query_json(r"""
SELECT User {
deck: {
id
} ORDER BY User.deck.cost DESC
LIMIT 1,
}
FILTER .name = 'Alice';
""")
res = json.loads(res)
# fetch the same data via an alias, that should be
# functionally identical
await self.assert_query_result(
r"""
SELECT UserAlias {
deck,
}
FILTER .name = 'Alice';
""",
res
) | )
res = json.loads(res)
# fetch the same data via an alias, that should be
# functionally identical
await self.assert_query_result(
r | test_edgeql_aliases_clauses_01 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_ignore_alias(self):
await self.con.execute('''
CREATE ALIAS UserAlias2 := (
SELECT User {
deck: {
id
} ORDER BY User.deck.cost DESC
LIMIT 1,
}
);
''')
# Explicitly reset the default module alias to test
# that aliases don't care.
await self.con.execute('''
SET MODULE std;
''')
await self.assert_query_result(
r"""
SELECT default::UserAlias2 {
deck,
}
FILTER .name = 'Alice';
""",
[{
'deck': [
{}
]
}]
) | )
# Explicitly reset the default module alias to test
# that aliases don't care.
await self.con.execute( | test_edgeql_aliases_ignore_alias | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_esdl_01(self):
await self.assert_query_result(
r"""
SELECT WaterOrEarthCard {
name,
owned_by_alice,
}
FILTER any(.name ILIKE {'%turtle%', 'dwarf'})
ORDER BY .name;
""",
[
{
'name': 'Dwarf',
'owned_by_alice': True,
},
{
'name': 'Giant turtle',
'owned_by_alice': True,
},
]
)
await self.assert_query_result(
r"""
SELECT EarthOrFireCard {
name,
}
FILTER .name IN {'Imp', 'Dwarf'}
ORDER BY .name;
""",
[
{
'name': 'Dwarf'
},
{
'name': 'Imp'
},
]
) | ,
[
{
'name': 'Dwarf',
'owned_by_alice': True,
},
{
'name': 'Giant turtle',
'owned_by_alice': True,
},
]
)
await self.assert_query_result(
r | test_edgeql_aliases_esdl_01 | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def test_edgeql_aliases_introspection(self):
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Type {
name
}
FILTER .from_alias AND .name LIKE 'default::Air%'
ORDER BY .name
""",
[{
'name': 'default::AirCard',
}]
)
await self.con.execute('''
CREATE ALIAS tuple_alias := ('foo', 10);
''')
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT Tuple {
name,
element_types: {
name := .type.name
} ORDER BY @index
}
FILTER
.from_alias
AND .name = 'default::tuple_alias'
ORDER BY .name
""",
[{
'name': 'default::tuple_alias',
'element_types': [{
'name': 'std::str',
}, {
'name': 'std::int64',
}]
}]
)
await self.assert_query_result(
r"""
select schema::Pointer {name, target: {from_alias}}
filter .name = 'winner'
and .source.name = 'default::AwardAlias'
""",
[{"name": "winner", "target": {"from_alias": True}}]
) | ,
[{
'name': 'default::AirCard',
}]
)
await self.con.execute( | test_edgeql_aliases_introspection | python | geldata/gel | tests/test_edgeql_expr_aliases.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_expr_aliases.py | Apache-2.0 |
async def _test_proto_state_change_in_tx(self):
# Collect states
await self._execute('''
SET MODULE TestStateChangeInTx
''')
cc = await self.con.recv_match(protocol.CommandComplete)
await self.con.recv_match(protocol.ReadyForCommand)
await self._execute('''
CONFIGURE SESSION SET allow_user_specified_id := true
''', cc=cc)
cc_true = await self.con.recv_match(protocol.CommandComplete)
await self.con.recv_match(protocol.ReadyForCommand)
await self._execute('''
CONFIGURE SESSION SET allow_user_specified_id := false
''')
cc_false = await self.con.recv_match(protocol.CommandComplete)
await self.con.recv_match(protocol.ReadyForCommand)
# Start a transaction that doesn't allow_user_specified_id
await self._execute('START TRANSACTION', cc=cc_false)
await self.con.recv_match(protocol.CommandComplete)
await self.con.recv_match(protocol.ReadyForCommand)
# But insert with session that does allow_user_specified_id
await self._execute('''
INSERT StateChangeInTx {
id := <uuid>'a768e9d5-d908-4072-b370-865b450216ff'
};
''', cc=cc_true)
await self.con.recv_match(
protocol.CommandComplete,
status='INSERT'
)
await self.con.recv_match(protocol.ReadyForCommand) | )
cc = await self.con.recv_match(protocol.CommandComplete)
await self.con.recv_match(protocol.ReadyForCommand)
await self._execute( | _test_proto_state_change_in_tx | python | geldata/gel | tests/test_protocol.py | https://github.com/geldata/gel/blob/master/tests/test_protocol.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_01(self):
"""
SELECT User.deck
FILTER User.name
""" | SELECT User.deck
FILTER User.name | test_edgeql_ir_scope_tree_bad_01 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_02(self):
"""
SELECT User.deck
FILTER User.deck@count
""" | SELECT User.deck
FILTER User.deck@count | test_edgeql_ir_scope_tree_bad_02 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_03(self):
"""
SELECT User.deck { foo := User }
""" | SELECT User.deck { foo := User } | test_edgeql_ir_scope_tree_bad_03 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_04(self):
"""
UPDATE User.deck SET { name := User.name }
""" | UPDATE User.deck SET { name := User.name } | test_edgeql_ir_scope_tree_bad_04 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_05(self):
"""
WITH
U := User {id, r := random()}
SELECT
(
users := array_agg((SELECT U.id ORDER BY U.r LIMIT 10))
)
""" | WITH
U := User {id, r := random()}
SELECT
(
users := array_agg((SELECT U.id ORDER BY U.r LIMIT 10))
) | test_edgeql_ir_scope_tree_bad_05 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
def test_edgeql_ir_scope_tree_bad_06(self):
"""
UPDATE User SET { avatar := (UPDATE .avatar SET { text := "foo" }) }
""" | UPDATE User SET { avatar := (UPDATE .avatar SET { text := "foo" }) } | test_edgeql_ir_scope_tree_bad_06 | python | geldata/gel | tests/test_edgeql_ir_scopetree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_scopetree.py | Apache-2.0 |
async def test_edgeql_policies_03(self):
vals = await self.con.query('''
select Object.id
''')
self.assertEqual(len(vals), len(set(vals)))
await self.con.execute('''
create alias foo := Issue;
''')
vals = await self.con.query('''
select BaseObject.id
''')
self.assertEqual(len(vals), len(set(vals))) | )
self.assertEqual(len(vals), len(set(vals)))
await self.con.execute( | test_edgeql_policies_03 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_09(self):
# Create a type that we can write but not view
await self.con.execute('''
create type X extending Dictionary {
create access policy can_insert allow insert;
};
insert X { name := "!" };
''')
# We need to raise a constraint violation error even though
# we are trying to do unless conflict, because we can't see
# the conflicting object!
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r"name violates exclusivity constraint"):
await self.con.query('''
insert X { name := "!" }
unless conflict on (.name) else (select X)
''') | )
# We need to raise a constraint violation error even though
# we are trying to do unless conflict, because we can't see
# the conflicting object!
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
r"name violates exclusivity constraint"):
await self.con.query( | test_edgeql_policies_09 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_12(self):
await self.con.query('''
create global cur_user_obj := (
select User filter .name = global cur_user);
alter type User {
create access policy allow_self_obj
allow all
using (__subject__ ?= global cur_user_obj);
}
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on insert of default::User"):
await self.con.query('''
insert User { name := 'whatever' }
''') | )
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on insert of default::User"):
await self.con.query( | test_edgeql_policies_12 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_scope_01(self):
await self.con.execute('''
create type Foo {
create required property val -> int64;
};
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r'possibly an empty set returned'):
await self.con.execute('''
alter type Foo {
create access policy pol allow all using(Foo.val > 5);
};
''') | )
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
r'possibly an empty set returned'):
await self.con.execute( | test_edgeql_policies_scope_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_volatile_01(self):
await self.con.execute('''
create type Bar {
create required property r -> float64;
create access policy ok allow all;
create access policy no deny
update write, insert using (.r <= 0.5);
};
''')
for _ in range(10):
async with self._run_and_rollback():
try:
await self.con.execute('''
insert Bar { r := random() };
''')
except edgedb.AccessPolicyError:
# If it failed, nothing to do, keep trying
pass
else:
r = (await self.con.query('''
select Bar.r
'''))[0]
self.assertGreater(r, 0.5)
await self.con.execute('''
insert Bar { r := 1.0 };
''')
for _ in range(10):
async with self._run_and_rollback():
try:
await self.con.execute('''
update Bar set { r := random() };
''')
except edgedb.AccessPolicyError:
# If it failed, nothing to do, keep trying
pass
else:
r = (await self.con.query('''
select Bar.r
'''))[0]
self.assertGreater(r, 0.5) | )
for _ in range(10):
async with self._run_and_rollback():
try:
await self.con.execute( | test_edgeql_policies_volatile_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_messages(self):
await self.con.execute(
'''
create type NoAllows {
create access policy allow_select
allow select;
};
create type TwoAllows {
create required property val -> str;
create access policy allow_insert_of_a
allow insert using (.val = 'a')
{ set errmessage := 'you can insert a' };
create access policy allow_insert_of_b
allow insert using (.val = 'b');
};
create type ThreeDenies {
create required property val -> str;
create access policy allow_insert
allow insert;
create access policy deny_starting_with_f
deny insert using (.val[0] = 'f')
{ set errmessage := 'val cannot start with f' };
create access policy deny_foo
deny insert using (.val = 'foo')
{ set errmessage := 'val cannot be foo' };
create access policy deny_bar
deny insert using (.val = 'bar');
};
'''
)
await self.con.execute("insert TwoAllows { val := 'a' };")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on insert of default::NoAllows$",
):
await self.con.query('insert NoAllows')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError, r"\(you can insert a\)$"
):
await self.con.query("insert TwoAllows { val := 'c' }")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
"access policy violation.*val cannot.*val cannot",
):
await self.con.query("insert ThreeDenies { val := 'foo' }")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
"access policy violation on insert of default::ThreeDenies$",
):
await self.con.query("insert ThreeDenies { val := 'bar' }") | create type NoAllows {
create access policy allow_select
allow select;
};
create type TwoAllows {
create required property val -> str;
create access policy allow_insert_of_a
allow insert using (.val = 'a')
{ set errmessage := 'you can insert a' };
create access policy allow_insert_of_b
allow insert using (.val = 'b');
};
create type ThreeDenies {
create required property val -> str;
create access policy allow_insert
allow insert;
create access policy deny_starting_with_f
deny insert using (.val[0] = 'f')
{ set errmessage := 'val cannot start with f' };
create access policy deny_foo
deny insert using (.val = 'foo')
{ set errmessage := 'val cannot be foo' };
create access policy deny_bar
deny insert using (.val = 'bar');
}; | test_edgeql_policies_messages | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_namespace(self):
# ... we were accidentally skipping some important fixups in
# access policy compilation
await self.con.execute(
'''
create type X {
create access policy foo
allow all using (
count((
WITH X := {1, 2}
SELECT (X, (FOR x in {X} UNION (SELECT x)))
)) = 2);
};
insert X;
'''
)
await self.assert_query_result(
r'''select X''',
[{}],
) | create type X {
create access policy foo
allow all using (
count((
WITH X := {1, 2}
SELECT (X, (FOR x in {X} UNION (SELECT x)))
)) = 2);
};
insert X; | test_edgeql_policies_namespace | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_function_01(self):
await self.con.execute('''
set global filter_owned := true;
''')
await self.assert_query_result(
r'''select (count(Issue), count_Issue())''',
[(0, 0)],
)
await self.con.execute('''
configure session set apply_access_policies := false;
''')
await self.assert_query_result(
r'''select (count(Issue), count_Issue())''',
[(4, 4)],
) | )
await self.assert_query_result(
r'''select (count(Issue), count_Issue())''',
[(0, 0)],
)
await self.con.execute( | test_edgeql_policies_function_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_complex_01(self):
await self.migrate(
"""
abstract type Auditable {
access policy auditable_default
allow all ;
access policy auditable_prohibit_hard_deletes
deny delete {
errmessage := 'hard deletes are disallowed';
};
delegated constraint std::expression on
((.updated_at >= .created_at))
except (NOT (EXISTS (.updated_at)));
delegated constraint std::expression on
((.deleted_at > .created_at))
except (NOT (EXISTS (.deleted_at)));
required property created_at: std::datetime {
default := (std::datetime_of_statement());
readonly := true;
};
property deleted_at: std::datetime;
required property uid: std::str {
default := <str>random();
readonly := true;
constraint std::exclusive;
};
property updated_at: std::datetime {
rewrite
update
using (std::datetime_of_statement());
};
};
type Avatar extending default::Auditable {
link owner := (.<avatar[is default::Member]);
required property url: std::str;
};
type Member extending default::Auditable {
link avatar: default::Avatar {
on source delete delete target if orphan;
on target delete allow;
constraint std::exclusive;
};
};
"""
)
await self.con.execute(
'''
update Avatar set {deleted_at:=datetime_of_statement()};
'''
) | abstract type Auditable {
access policy auditable_default
allow all ;
access policy auditable_prohibit_hard_deletes
deny delete {
errmessage := 'hard deletes are disallowed';
};
delegated constraint std::expression on
((.updated_at >= .created_at))
except (NOT (EXISTS (.updated_at)));
delegated constraint std::expression on
((.deleted_at > .created_at))
except (NOT (EXISTS (.deleted_at)));
required property created_at: std::datetime {
default := (std::datetime_of_statement());
readonly := true;
};
property deleted_at: std::datetime;
required property uid: std::str {
default := <str>random();
readonly := true;
constraint std::exclusive;
};
property updated_at: std::datetime {
rewrite
update
using (std::datetime_of_statement());
};
};
type Avatar extending default::Auditable {
link owner := (.<avatar[is default::Member]);
required property url: std::str;
};
type Member extending default::Auditable {
link avatar: default::Avatar {
on source delete delete target if orphan;
on target delete allow;
constraint std::exclusive;
};
}; | test_edgeql_policies_complex_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_optional_leakage_01(self):
await self.con.execute(
'''
CREATE GLOBAL current_user -> uuid;
CREATE TYPE Org {
CREATE REQUIRED PROPERTY domain -> str {
CREATE CONSTRAINT exclusive;
};
CREATE PROPERTY name -> str;
};
CREATE TYPE User2 {
CREATE REQUIRED LINK org -> Org;
CREATE REQUIRED PROPERTY email -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE GLOBAL current_user_object := (SELECT
User2
FILTER
(.id = GLOBAL current_user)
);
CREATE TYPE Src {
CREATE REQUIRED SINGLE LINK org -> Org;
CREATE SINGLE LINK user -> User2;
CREATE ACCESS POLICY deny_no
DENY ALL USING (
(((GLOBAL current_user_object).org != .org) ?? true));
CREATE ACCESS POLICY yes
ALLOW ALL USING (SELECT
((GLOBAL current_user = .user.id) ?? false)
);
};
'''
)
await self.con.execute('''
configure session set apply_access_policies := false;
''')
await self.con.execute('''
insert User2 {
email:= "[email protected]",
org:=(insert Org {domain:="a.com"}),
};
''')
res = await self.con.query_single('''
insert User2 {
email:= "[email protected]",
org:=(insert Org {domain:="b.com"}),
};
''')
await self.con.execute('''
insert Src {
org := (select Org filter .domain = "a.com")
};
''')
await self.con.execute('''
configure session set apply_access_policies := true;
''')
await self.con.execute(f'''
set global current_user := <uuid>'{res.id}';
''')
await self.assert_query_result(
r'''select Src''',
[],
) | CREATE GLOBAL current_user -> uuid;
CREATE TYPE Org {
CREATE REQUIRED PROPERTY domain -> str {
CREATE CONSTRAINT exclusive;
};
CREATE PROPERTY name -> str;
};
CREATE TYPE User2 {
CREATE REQUIRED LINK org -> Org;
CREATE REQUIRED PROPERTY email -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE GLOBAL current_user_object := (SELECT
User2
FILTER
(.id = GLOBAL current_user)
);
CREATE TYPE Src {
CREATE REQUIRED SINGLE LINK org -> Org;
CREATE SINGLE LINK user -> User2;
CREATE ACCESS POLICY deny_no
DENY ALL USING (
(((GLOBAL current_user_object).org != .org) ?? true));
CREATE ACCESS POLICY yes
ALLOW ALL USING (SELECT
((GLOBAL current_user = .user.id) ?? false)
);
}; | test_edgeql_policies_optional_leakage_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
async def test_edgeql_policies_global_01(self):
# GH issue #6404
clan_and_global = '''
type Clan {
access policy allow_select_players
allow select
using (
global current_player.clan.id ?= .id
);
};
global current_player_id: uuid;
global current_player := (
select Player filter .id = global current_player_id
);
'''
await self.migrate(
'''
type Principal;
type Player extending Principal {
required link clan: Clan;
}
''' + clan_and_global
)
await self.migrate(
'''
type Player {
required link clan: Clan;
}
''' + clan_and_global
) | await self.migrate( | test_edgeql_policies_global_01 | python | geldata/gel | tests/test_edgeql_policies.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_policies.py | Apache-2.0 |
def get_setup_script(cls):
res = super().get_setup_script()
# HACK: As a debugging cycle hack, when RELOAD is true, we reload the
# extension package from the file, so we can test without a bootstrap.
RELOAD = False
if RELOAD:
root = pathlib.Path(__file__).parent.parent
with open(root / 'edb/lib/ext/ai.edgeql') as f:
contents = f.read()
to_add = (
'''
drop extension package ai version '1.0';
create extension ai;
'''
+ contents
)
splice = '__internal_testmode := true;'
res = res.replace(splice, splice + to_add)
return res | drop extension package ai version '1.0';
create extension ai; | get_setup_script | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
async def test_ext_ai_indexing_01(self):
try:
await self.con.execute(
"""
insert Astronomy {
content := 'Skies on Mars are red'
};
insert Astronomy {
content := 'Skies on Earth are blue'
};
""",
)
await self.assert_query_result(
'''
select _ := ext::ai::to_context((select Astronomy))
order by _
''',
[
'Skies on Earth are blue',
'Skies on Mars are red',
],
)
async for tr in self.try_until_succeeds(
ignore=(AssertionError,),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
r'''
with
result := ext::ai::search(
Astronomy, <array<float32>>$qv)
select
result.object {
content,
distance := result.distance,
}
order by
result.distance asc empty last
then result.object.content
''',
[
{
'content': 'Skies on Earth are blue',
'distance': 0.3675444679663241,
},
{
'content': 'Skies on Mars are red',
'distance': 0.4284523933505918,
},
],
variables={
"qv": [1 for i in range(10)],
}
)
finally:
await self.con.execute('''
delete Astronomy;
''') | insert Astronomy {
content := 'Skies on Mars are red'
};
insert Astronomy {
content := 'Skies on Earth are blue'
};
""",
)
await self.assert_query_result( | test_ext_ai_indexing_01 | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
async def test_ext_ai_indexing_02(self):
try:
qry = '''
with
result := ext::ai::search(
Stuff, <array<float32>>$qv)
select
result.object {
content,
content2,
distance := result.distance,
}
order by
result.distance asc empty last
then result.object.content;
'''
qv = [1 for i in range(10)]
await self.assert_query_result(
"""
insert Stuff {
content := 'Skies on Mars',
content2 := ' are red',
};
insert Stuff {
content := 'Skies on Earth',
content2 := ' are blue',
};
""" + qry,
[],
variables=dict(qv=qv),
)
await self.assert_query_result(
'''
select _ := ext::ai::to_context((select Stuff))
order by _
''',
[
'Skies on Earth are blue',
'Skies on Mars are red',
],
)
async for tr in self.try_until_succeeds(
ignore=(AssertionError,),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
qry,
[
{
'content': 'Skies on Earth',
'content2': ' are blue',
'distance': 0.3675444679663241,
},
{
'content': 'Skies on Mars',
'content2': ' are red',
'distance': 0.4284523933505918,
},
],
variables=dict(qv=qv),
)
# updating an object should make it disappear from results.
# (the read is done in the same tx, so there is no possible
# race where the worker picks it up before the read)
async for tr in self.try_until_succeeds(
ignore=(
edgedb.TransactionConflictError,
edgedb.TransactionSerializationError,
),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
"""
update Stuff filter .content like '%Earth'
set { content2 := ' are often grey' };
""" + qry,
[
{
'content': 'Skies on Mars',
'content2': ' are red',
'distance': 0.4284523933505918,
},
],
variables=dict(qv=qv),
)
finally:
await self.con.execute('''
delete Stuff;
''') | qv = [1 for i in range(10)]
await self.assert_query_result( | test_ext_ai_indexing_02 | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
async def test_ext_ai_indexing_03(self):
try:
await self.con.execute(
"""
insert Star {
content := 'Skies on Mars are red'
};
insert Supernova {
content := 'Skies on Earth are blue'
};
""",
)
await self.assert_query_result(
'''
select _ := ext::ai::to_context((select Star))
order by _
''',
[
'Skies on Earth are blue',
'Skies on Mars are red',
],
)
async for tr in self.try_until_succeeds(
ignore=(AssertionError,),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
r'''
with
result := ext::ai::search(
Star, <array<float32>>$qv)
select
result.object {
content,
distance := result.distance,
}
order by
result.distance asc empty last
then result.object.content
''',
[
{
'content': 'Skies on Earth are blue',
'distance': 0.3675444679663241,
},
{
'content': 'Skies on Mars are red',
'distance': 0.4284523933505918,
},
],
variables={
"qv": [1 for i in range(10)],
}
)
finally:
await self.con.execute('''
delete Star;
delete Supernova;
''') | insert Star {
content := 'Skies on Mars are red'
};
insert Supernova {
content := 'Skies on Earth are blue'
};
""",
)
await self.assert_query_result( | test_ext_ai_indexing_03 | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
async def test_ext_ai_indexing_04(self):
qv = [1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0, 9.0, -10.0]
await self._assert_index_use(
f'''
with vector := <array<float32>>$0
select ext::ai::search(Stuff, vector) limit 5;
''',
qv,
)
await self._assert_index_use(
f'''
with vector := <array<float32>>$0
select ext::ai::search(Stuff, vector).object limit 5;
''',
qv,
)
await self._assert_index_use(
f'''
select ext::ai::search(Stuff, <array<float32>>$0) limit 5;
''',
qv,
)
await self._assert_index_use(
f'''
with vector := <array<float32>><json>$0
select ext::ai::search(Stuff, vector) limit 5;
''',
json.dumps(qv),
)
await self._assert_index_use(
f'''
select ext::ai::search(Stuff, <array<float32>><json>$0) limit 5;
''',
json.dumps(qv),
) | ,
qv,
)
await self._assert_index_use(
f | test_ext_ai_indexing_04 | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
async def test_ext_ai_indexing_05(self):
try:
await self.con.execute(
"""
insert Astronomy {
content := 'Skies on Venus are orange'
};
insert Astronomy {
content := 'Skies on Mars are red'
};
insert Astronomy {
content := 'Skies on Pluto are black and starry'
};
insert Astronomy {
content := 'Skies on Earth are blue'
};
""",
)
async for tr in self.try_until_succeeds(
ignore=(AssertionError,),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
r'''
with
result := ext::ai::search(
Astronomy, <array<float32>>$qv)
select
result.object {
content,
distance := result.distance,
}
order by
result.distance asc empty last
then result.object.content
''',
[
{
'content': (
'Skies on Pluto are black and starry'
),
'distance': 0.3545027756320972,
},
{
'content': 'Skies on Earth are blue',
'distance': 0.3675444679663241,
},
{
'content': 'Skies on Mars are red',
'distance': 0.4284523933505918,
},
{
'content': 'Skies on Venus are orange',
'distance': 0.4606401100294063,
},
],
variables={
"qv": [1 for i in range(10)],
}
)
finally:
await self.con.execute('''
delete Astronomy;
''') | insert Astronomy {
content := 'Skies on Venus are orange'
};
insert Astronomy {
content := 'Skies on Mars are red'
};
insert Astronomy {
content := 'Skies on Pluto are black and starry'
};
insert Astronomy {
content := 'Skies on Earth are blue'
};
""",
)
async for tr in self.try_until_succeeds(
ignore=(AssertionError,),
timeout=30.0,
):
async with tr:
await self.assert_query_result(
r | test_ext_ai_indexing_05 | python | geldata/gel | tests/test_ext_ai.py | https://github.com/geldata/gel/blob/master/tests/test_ext_ai.py | Apache-2.0 |
def test_sql_parse_select_01(self):
"""
SELECT col1 FROM my_table WHERE
my_attribute LIKE 'condition' AND other = 5.6 AND extra > 5
% OK %
SELECT col1 FROM my_table WHERE
(((my_attribute LIKE 'condition') AND
(other = 5.6)) AND (extra > 5))
""" | SELECT col1 FROM my_table WHERE
my_attribute LIKE 'condition' AND other = 5.6 AND extra > 5
% OK %
SELECT col1 FROM my_table WHERE
(((my_attribute LIKE 'condition') AND
(other = 5.6)) AND (extra > 5)) | test_sql_parse_select_01 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_02(self):
"""
SELECT * FROM table_one JOIN table_two USING (common)
""" | SELECT * FROM table_one JOIN table_two USING (common) | test_sql_parse_select_02 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_03(self):
"""
WITH fake_table AS (
SELECT SUM(countable) AS total FROM inner_table
GROUP BY groupable
) SELECT * FROM fake_table
% OK %
WITH fake_table AS ((
SELECT sum(countable) AS total FROM inner_table
GROUP BY groupable
)) SELECT * FROM fake_table
""" | WITH fake_table AS (
SELECT SUM(countable) AS total FROM inner_table
GROUP BY groupable
) SELECT * FROM fake_table
% OK %
WITH fake_table AS ((
SELECT sum(countable) AS total FROM inner_table
GROUP BY groupable
)) SELECT * FROM fake_table | test_sql_parse_select_03 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_04(self):
"""
SELECT * FROM (SELECT something FROM dataset) AS other
""" | SELECT * FROM (SELECT something FROM dataset) AS other | test_sql_parse_select_04 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_05(self):
"""
SELECT a, CASE WHEN a=1 THEN 'one' WHEN a=2
THEN 'two' ELSE 'other' END FROM test
% OK %
SELECT a, (CASE WHEN (a = 1) THEN 'one' WHEN (a = 2)
THEN 'two' ELSE 'other' END) FROM test
""" | SELECT a, CASE WHEN a=1 THEN 'one' WHEN a=2
THEN 'two' ELSE 'other' END FROM test
% OK %
SELECT a, (CASE WHEN (a = 1) THEN 'one' WHEN (a = 2)
THEN 'two' ELSE 'other' END) FROM test | test_sql_parse_select_05 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_06(self):
"""
SELECT CASE a.value WHEN 0 THEN '1' ELSE '2' END
FROM sometable a
% OK %
SELECT (CASE a.value WHEN 0 THEN '1' ELSE '2' END)
FROM sometable AS a
""" | SELECT CASE a.value WHEN 0 THEN '1' ELSE '2' END
FROM sometable a
% OK %
SELECT (CASE a.value WHEN 0 THEN '1' ELSE '2' END)
FROM sometable AS a | test_sql_parse_select_06 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_07(self):
"""
SELECT * FROM table_one UNION select * FROM table_two
% OK %
(SELECT * FROM table_one) UNION (SELECT * FROM table_two)
""" | SELECT * FROM table_one UNION select * FROM table_two
% OK %
(SELECT * FROM table_one) UNION (SELECT * FROM table_two) | test_sql_parse_select_07 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_08(self):
"""
SELECT * FROM my_table WHERE ST_Intersects(geo1, geo2)
% OK %
SELECT * FROM my_table WHERE st_intersects(geo1, geo2)
""" | SELECT * FROM my_table WHERE ST_Intersects(geo1, geo2)
% OK %
SELECT * FROM my_table WHERE st_intersects(geo1, geo2) | test_sql_parse_select_08 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_09(self):
"""
SELECT 'accbf276-705b-11e7-b8e4-0242ac120002'::UUID
% OK %
SELECT ('accbf276-705b-11e7-b8e4-0242ac120002')::uuid
""" | SELECT 'accbf276-705b-11e7-b8e4-0242ac120002'::UUID
% OK %
SELECT ('accbf276-705b-11e7-b8e4-0242ac120002')::uuid | test_sql_parse_select_09 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_10(self):
"""
SELECT * FROM my_table ORDER BY field DESC NULLS FIRST
""" | SELECT * FROM my_table ORDER BY field DESC NULLS FIRST | test_sql_parse_select_10 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_11(self):
"""
SELECT * FROM my_table ORDER BY field
% OK %
SELECT * FROM my_table ORDER BY field ASC NULLS LAST
""" | SELECT * FROM my_table ORDER BY field
% OK %
SELECT * FROM my_table ORDER BY field ASC NULLS LAST | test_sql_parse_select_11 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_12(self):
"""
SELECT salary, sum(salary) OVER () FROM empsalary
""" | SELECT salary, sum(salary) OVER () FROM empsalary | test_sql_parse_select_12 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_13(self):
"""
SELECT salary, sum(salary)
OVER (ORDER BY salary) FROM empsalary
% OK %
SELECT salary, sum(salary)
OVER (ORDER BY salary ASC NULLS LAST) FROM empsalary
""" | SELECT salary, sum(salary)
OVER (ORDER BY salary) FROM empsalary
% OK %
SELECT salary, sum(salary)
OVER (ORDER BY salary ASC NULLS LAST) FROM empsalary | test_sql_parse_select_13 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_14(self):
"""
SELECT salary, avg(salary)
OVER (PARTITION BY depname) FROM empsalary
""" | SELECT salary, avg(salary)
OVER (PARTITION BY depname) FROM empsalary | test_sql_parse_select_14 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_15(self):
"""
SELECT m.* FROM mytable m WHERE m.foo IS NULL
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS NULL)
""" | SELECT m.* FROM mytable m WHERE m.foo IS NULL
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS NULL) | test_sql_parse_select_15 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_16(self):
"""
SELECT m.* FROM mytable m WHERE m.foo IS NOT NULL
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS NOT NULL)
""" | SELECT m.* FROM mytable m WHERE m.foo IS NOT NULL
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS NOT NULL) | test_sql_parse_select_16 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_17(self):
"""
SELECT m.* FROM mytable m WHERE m.foo IS TRUE
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS TRUE)
""" | SELECT m.* FROM mytable m WHERE m.foo IS TRUE
% OK %
SELECT m.* FROM mytable AS m WHERE (m.foo IS TRUE) | test_sql_parse_select_17 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_18(self):
"""
SELECT m.name AS mname, pname FROM manufacturers m,
LATERAL get_product_names(m.id) pname
% OK %
SELECT m.name AS mname, pname FROM manufacturers AS m,
LATERAL get_product_names(m.id) AS pname
""" | SELECT m.name AS mname, pname FROM manufacturers m,
LATERAL get_product_names(m.id) pname
% OK %
SELECT m.name AS mname, pname FROM manufacturers AS m,
LATERAL get_product_names(m.id) AS pname | test_sql_parse_select_18 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_19(self):
"""
SELECT * FROM unnest(ARRAY['a','b','c','d','e','f'])
% OK %
SELECT * FROM unnest(ARRAY['a', 'b', 'c', 'd', 'e', 'f'])
""" | SELECT * FROM unnest(ARRAY['a','b','c','d','e','f'])
% OK %
SELECT * FROM unnest(ARRAY['a', 'b', 'c', 'd', 'e', 'f']) | test_sql_parse_select_19 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_20(self):
"""
SELECT * FROM my_table
WHERE (a, b) in (('a', 'b'), ('c', 'd'))
% OK %
SELECT * FROM my_table
WHERE ((a, b) IN (('a', 'b'), ('c', 'd')))
""" | SELECT * FROM my_table
WHERE (a, b) in (('a', 'b'), ('c', 'd'))
% OK %
SELECT * FROM my_table
WHERE ((a, b) IN (('a', 'b'), ('c', 'd'))) | test_sql_parse_select_20 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_21(self):
"""
SELECT * FRO my_table
""" | SELECT * FRO my_table | test_sql_parse_select_21 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_22(self):
"""
SELECT a, CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN ELSE 'other' END FROM test
""" | SELECT a, CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN ELSE 'other' END FROM test | test_sql_parse_select_22 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_23(self):
"""
SELECT * FROM table_one, table_two
""" | SELECT * FROM table_one, table_two | test_sql_parse_select_23 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_24(self):
"""
SELECT * FROM table_one, public.table_one
""" | SELECT * FROM table_one, public.table_one | test_sql_parse_select_24 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_25(self):
"""
WITH fake_table AS (SELECT * FROM inner_table)
SELECT * FROM fake_table
% OK %
WITH fake_table AS ((SELECT * FROM inner_table))
SELECT * FROM fake_table
""" | WITH fake_table AS (SELECT * FROM inner_table)
SELECT * FROM fake_table
% OK %
WITH fake_table AS ((SELECT * FROM inner_table))
SELECT * FROM fake_table | test_sql_parse_select_25 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_26(self):
"""
SELECT * FROM table_one JOIN table_two USING (common_1)
JOIN table_three USING (common_2)
""" | SELECT * FROM table_one JOIN table_two USING (common_1)
JOIN table_three USING (common_2) | test_sql_parse_select_26 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_27(self):
"""
select * FROM table_one UNION select * FROM table_two
% OK %
(SELECT * FROM table_one) UNION (SELECT * FROM table_two)
""" | select * FROM table_one UNION select * FROM table_two
% OK %
(SELECT * FROM table_one) UNION (SELECT * FROM table_two) | test_sql_parse_select_27 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_28(self):
"""
SELECT * FROM my_table WHERE (a, b) in ('a', 'b')
% OK %
SELECT * FROM my_table WHERE ((a, b) IN ('a', 'b'))
""" | SELECT * FROM my_table WHERE (a, b) in ('a', 'b')
% OK %
SELECT * FROM my_table WHERE ((a, b) IN ('a', 'b')) | test_sql_parse_select_28 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_30(self):
"""
SELECT (SELECT * FROM table_one)
% OK %
SELECT ((SELECT * FROM table_one))
""" | SELECT (SELECT * FROM table_one)
% OK %
SELECT ((SELECT * FROM table_one)) | test_sql_parse_select_30 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_31(self):
"""
SELECT my_func((select * from table_one))
% OK %
SELECT my_func(((SELECT * FROM table_one)))
""" | SELECT my_func((select * from table_one))
% OK %
SELECT my_func(((SELECT * FROM table_one))) | test_sql_parse_select_31 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_32(self):
"""
SELECT 1
""" | SELECT 1 | test_sql_parse_select_32 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
def test_sql_parse_select_33(self):
"""
SELECT 2
""" | SELECT 2 | test_sql_parse_select_33 | python | geldata/gel | tests/test_sql_parse.py | https://github.com/geldata/gel/blob/master/tests/test_sql_parse.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.