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_migration_to_computed_drop_exclusive(self): await self.migrate(r''' type User { multi posts: Post { constraint exclusive; } multi foo: int64 { constraint exclusive; } bar: int64 { constraint exclusive; } } type Post; ''') await self.migrate(r''' type User { multi link posts := .<user[is Post]; multi property foo := Post.num; property bar := -1; } type Post { user: User; num: int64; } ''')
) await self.migrate(r
test_edgeql_migration_to_computed_drop_exclusive
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_between_computeds_01(self): await self.migrate(r''' type Away { x: str; property y { using (.x ++ "!"); constraint exclusive; } }; type Away2 extending Away; ''') await self.migrate(r''' type Away { x: str; property y -> str { constraint exclusive; } }; type Away2 extending Away; ''')
) await self.migrate(r
test_edgeql_migration_between_computeds_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_between_computeds_02(self): await self.migrate(r''' type Away { x: str; property y { using (.x); constraint exclusive; } }; type Away2 extending Away; ''') await self.migrate(r''' type Away { x: str; property y { using (.x ++ "!"); constraint exclusive; } }; type Away2 extending Away; ''') await self.migrate(r''' type Away { x: str; property y { using (.x); constraint exclusive; } }; type Away2 extending Away; ''') await self.migrate(r''' type Away { x: str; property y -> str { constraint exclusive; } }; type Away2 extending Away; ''')
) await self.migrate(r
test_edgeql_migration_between_computeds_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_alias_new_computed_01(self): await self.migrate(r''' global a_id -> str; global current_user := ( select User filter .x_id = global a_id); type User { required property x_id -> str { constraint exclusive; } } ''') await self.migrate(r''' global a_id -> str; global current_user := ( select User filter .x_id = global a_id); type User { required property x_id -> str { constraint exclusive; } required property a_id := .x_id; } ''')
) await self.migrate(r
test_edgeql_migration_alias_new_computed_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_alias_new_computed_02(self): await self.migrate(r''' global a_id -> str; alias current_user := ( select User filter .x_id = global a_id); type User { required property x_id -> str { constraint exclusive; } } ''') await self.migrate(r''' global a_id -> str; alias current_user := ( select User filter .x_id = global a_id); type User { required property x_id -> str { constraint exclusive; } required property a_id := .x_id; } ''')
) await self.migrate(r
test_edgeql_migration_alias_new_computed_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_trigger_shift_01(self): await self.migrate(r''' type Log { body: str; timestamp: datetime { default := datetime_current(); } } abstract type Named { required name: str; } type Person extending Named { trigger log_insert after insert for each when (false) do ( insert Log { body := __new__.__type__.name ++ ' ' ++ __new__.name, } ); } ''') await self.migrate(r''' type Log { body: str; timestamp: datetime { default := datetime_current(); } } abstract type Named { required name: str; trigger log_insert after insert for each when (false) do ( insert Log { body := __new__.__type__.name ++ ' ' ++ __new__.name, } ); } type Person extending Named { } ''') await self.migrate(r''' type Log { body: str; timestamp: datetime { default := datetime_current(); } } abstract type Named { required name: str; trigger log_insert after insert for each when (true) do ( insert Log { body := __new__.__type__.name ++ ' ' ++ __new__.name, } ); } type Person extending Named { } ''')
) await self.migrate(r
test_edgeql_migration_trigger_shift_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_eq_collections_25(self): await self.con.execute(r""" START MIGRATION TO { module test { alias Foo := [20]; } }; POPULATE MIGRATION; COMMIT MIGRATION; """) await self.con.execute(r""" START MIGRATION TO { module test { } }; POPULATE MIGRATION; COMMIT MIGRATION; """)
) await self.con.execute(r
test_edgeql_migration_eq_collections_25
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_ddl_collection_cleanup_06(self): for _ in range(2): await self.con.execute(r""" CREATE FUNCTION cleanup_06( a: int64 ) -> tuple<int64, tuple<int64>> USING EdgeQL $$ SELECT (a, ((a + 1),)) $$; """) await self.con.execute(r""" DROP FUNCTION cleanup_06(a: int64) """)
) await self.con.execute(r
test_edgeql_ddl_collection_cleanup_06
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_enum_01(self): # Test some enum stuff. This needs to be nonisolated because postgres # won't let you *use* an enum until it has been committed! await self.migrate(''' scalar type Status extending enum<pending, in_progress, finished>; scalar type ImportStatus extending Status; scalar type ImportAnalyticsStatus extending Status; type Foo { property x -> ImportStatus }; ''') await self.con.execute(''' with module test insert Foo { x := 'pending' }; ''') await self.migrate(''' scalar type Status extending enum< pending, in_progress, finished, wontfix>; scalar type ImportStatus extending Status; scalar type ImportAnalyticsStatus extending Status; type Foo { property x -> ImportStatus }; function f(x: Status) -> str USING (<str>x); ''') await self.migrate(''' scalar type Status extending enum< pending, in_progress, finished, wontfix, again>; scalar type ImportStatus extending Status; scalar type ImportAnalyticsStatus extending Status; type Foo { property x -> ImportStatus }; function f(x: Status) -> str USING (<str>x); ''') await self.assert_query_result( r""" with module test select <ImportStatus>'wontfix' """, ['wontfix'], ) await self.assert_query_result( r""" with module test select f(<ImportStatus>'wontfix') """, ['wontfix'], ) # Retry for https://github.com/edgedb/edgedb/issues/7553 async for tr in self.try_until_succeeds( ignore_regexp="cannot drop type .* " "because other objects depend on it", ): async with tr: await self.migrate(''' scalar type Status extending enum< pending, in_progress, wontfix, again>; scalar type ImportStatus extending Status; scalar type ImportAnalyticsStatus extending Status; type Foo { property x -> ImportStatus }; function f(x: Status) -> str USING (<str>x); ''') await self.migrate('')
) await self.con.execute(
test_edgeql_migration_enum_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_splat_01(self): await self.migrate(''' type Foo { property bar := (select <json>Bar { ** }) } type Bar { property a -> str; link foo -> Foo; } ''') await self.migrate(''' type Foo { property bar := (<json>{}) } ''')
) await self.migrate(
test_edgeql_migration_splat_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_recovery(self): await self.con.execute(r""" START MIGRATION TO { module test { type Foo; } }; """) await self.con.execute('POPULATE MIGRATION') with self.assertRaises(edgedb.EdgeQLSyntaxError): await self.con.execute(r""" ALTER TYPE Foo; """) with self.assertRaises(edgedb.TransactionError): await self.con.execute("COMMIT MIGRATION") await self.con.execute("ABORT MIGRATION") self.assertEqual(await self.con.query_single("SELECT 1"), 1)
) await self.con.execute('POPULATE MIGRATION') with self.assertRaises(edgedb.EdgeQLSyntaxError): await self.con.execute(r
test_edgeql_migration_recovery
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_recovery_in_tx(self): await self.con.execute("START TRANSACTION") try: await self.con.execute("CREATE TYPE Bar") await self.con.execute(r""" START MIGRATION TO { module test { type Foo; } }; """) with self.assertRaises(edgedb.EdgeQLSyntaxError): await self.con.execute(r""" ALTER TYPE Foo; """) await self.con.execute("ABORT MIGRATION") self.assertEqual(await self.con.query("SELECT Bar"), []) finally: await self.con.execute("ROLLBACK")
) with self.assertRaises(edgedb.EdgeQLSyntaxError): await self.con.execute(r
test_edgeql_migration_recovery_in_tx
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_recovery_in_script(self): await self.migrate(""" type Base; """) await self.con.execute(""" SET MODULE test; INSERT Base; """) res = await self.con.query(r""" CREATE TYPE Bar; START MIGRATION TO { module test { type Base { required property name -> str; } } }; POPULATE MIGRATION; ABORT MIGRATION; SELECT Bar; """) self.assertEqual(res, []) await self.migrate('')
) await self.con.execute(
test_edgeql_migration_recovery_in_script
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_reset_schema(self): await self.migrate(r''' type Bar; alias Alias := Bar {val := 42}; ''') await self.migrate(r''' type Foo { property name -> str; link comp := Bar; }; type Bar; ''') res = await self.con.query(''' select schema::ObjectType { name } filter .name ilike 'test::%' ''') self.assertEqual(len(res), 2) await self.con.query('reset schema to initial') await self.assert_last_migration() res = await self.con.query(''' select schema::ObjectType { name } filter .name ilike 'test::%' ''') self.assertEqual(res, []) res = await self.con.query(''' select schema::Migration { script, name }; ''') self.assertEqual(res, []) await self.migrate(r''' type SomethingElse; ''') res = await self.con.query(''' select schema::Migration { script, name }; ''') self.assertEqual(len(res), 1)
) await self.migrate(r
test_edgeql_migration_reset_schema
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_extension_01(self): # Test migrations getting from an array in integers to vector and then # revert to an array of floats. await self.migrate(''' module default { type Foo { required data: array<int64> } } ''', explicit_modules=True) # Populate with some data. await self.con.execute(''' insert Foo {data := [3, 1, 4]}; insert Foo {data := [5, 6, 0]}; ''') # Add vector and migrate automatically (because we have an assignment # cast available from array<int64> to vector). await self.migrate(''' using extension pgvector version '0.5'; module default { scalar type v3 extending ext::pgvector::vector<3>; type Foo { property data: v3; }; } ''', explicit_modules=True) await self.assert_query_result( r""" select Foo.data """, tb.bag([[3, 1, 4], [5, 6, 0]]), json_only=True, ) await self.migrate( ''' module default { type Foo { property data: array<float32>; }; } ''', explicit_modules=True, # This migration needs the conversion expression user_input=["<array<float32>>.data"] ) await self.assert_query_result( r""" select Foo.data """, tb.bag([[3, 1, 4], [5, 6, 0]]), )
, explicit_modules=True) # Populate with some data. await self.con.execute(
test_edgeql_migration_extension_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_01(self): await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); } }; ''', explicit_modules=True) await self.migrate(''' using extension ai; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_02(self): await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); } }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-large' ) on (.content); } }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); } }; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_04(self): # Try changing embedding_model_max_output_dimensions on a # custom EmbeddingModel await self.migrate(''' using extension ai; module default { type TestEmbeddingModel extending ext::ai::EmbeddingModel { annotation ext::ai::model_name := "text-embedding-test"; annotation ext::ai::model_provider := "custom::test"; annotation ext::ai::embedding_model_max_input_tokens := "8191"; annotation ext::ai::embedding_model_max_batch_tokens := "16384"; annotation ext::ai::embedding_model_max_output_dimensions := "10"; annotation ext::ai::embedding_model_supports_shortening := "true"; }; type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-test' ) on (.content); }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type TestEmbeddingModel extending ext::ai::EmbeddingModel { annotation ext::ai::model_name := "text-embedding-test"; annotation ext::ai::model_provider := "custom::test"; annotation ext::ai::embedding_model_max_input_tokens := "8191"; annotation ext::ai::embedding_model_max_batch_tokens := "16384"; annotation ext::ai::embedding_model_max_output_dimensions := "20"; annotation ext::ai::embedding_model_supports_shortening := "true"; }; type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-test' ) on (.content); }; }; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_04
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_05(self): # Try changing the name of a model (and the type, too, though # that is not hugely relevant.) await self.migrate(''' using extension ai; module default { type TestEmbeddingModel extending ext::ai::EmbeddingModel { annotation ext::ai::model_name := "text-embedding-test"; annotation ext::ai::model_provider := "custom::test"; annotation ext::ai::embedding_model_max_input_tokens := "8191"; annotation ext::ai::embedding_model_max_batch_tokens := "16384"; annotation ext::ai::embedding_model_max_output_dimensions := "10"; annotation ext::ai::embedding_model_supports_shortening := "true"; }; type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-test' ) on (.content); }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type TestEmbeddingModel2 extending ext::ai::EmbeddingModel { annotation ext::ai::model_name := "text-embedding-test-2"; annotation ext::ai::model_provider := "custom::test"; annotation ext::ai::embedding_model_max_input_tokens := "8191"; annotation ext::ai::embedding_model_max_batch_tokens := "16384"; annotation ext::ai::embedding_model_max_output_dimensions := "10"; annotation ext::ai::embedding_model_supports_shortening := "true"; }; type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-test' ) on (.content); }; }; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_05
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_07a(self): await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Astronomy { deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_07a
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_07b(self): await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Astronomy; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_07b
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_07c(self): await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Astronomy { }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Astronomy { deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; module default { type Astronomy { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Astronomy { }; }; ''', explicit_modules=True) await self.migrate(''' using extension ai; ''', explicit_modules=True)
, explicit_modules=True) await self.migrate(
test_edgeql_migration_ai_07c
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_08(self): await self.migrate(''' using extension ai; module default { type Base { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Base { # deferred index ext::ai::index( # embedding_model := 'text-embedding-3-small' # ) on (.content ++ '!'); }; }; ''', explicit_modules=True) arg = [0.0] * 1536 await self.con.query(''' select { base := ext::ai::search(Base, <array<float32>>$0), sub := ext::ai::search(Sub, <array<float32>>$0), } ''', arg) await self.migrate(''' using extension ai; module default { type Base { content: str; deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content); }; type Sub extending Base { deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content ++ '!'); }; }; ''', explicit_modules=True) await self.con.query(''' select { base := ext::ai::search(Base, <array<float32>>$0), sub := ext::ai::search(Sub, <array<float32>>$0), } ''', arg) await self.migrate(''' using extension ai; module default { type Base { content: str; }; type Sub extending Base { deferred index ext::ai::index( embedding_model := 'text-embedding-3-small' ) on (.content ++ '!'); }; }; ''', explicit_modules=True) # Base lost the index, just select Sub await self.con.query(''' select { sub := ext::ai::search(Sub, <array<float32>>$0), } ''', arg)
, explicit_modules=True) arg = [0.0] * 1536 await self.con.query(
test_edgeql_migration_ai_08
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_ai_10(self): # EmbeddingModel with default embedding_model_max_batch_tokens. await self.migrate(''' using extension ai; module default { type TestEmbeddingModel extending ext::ai::EmbeddingModel { annotation ext::ai::model_name := "text-embedding-test"; annotation ext::ai::model_provider := "custom::test"; annotation ext::ai::embedding_model_max_input_tokens := "8191"; annotation ext::ai::embedding_model_max_output_dimensions := "10"; annotation ext::ai::embedding_model_supports_shortening := "true"; }; }; ''', explicit_modules=True) await self.assert_query_result( r""" with model := ( select schema::ObjectType { x := ( for ann in .annotations select ann@value filter ann.name = 'ext::ai::embedding_model_max_batch_tokens' ) } filter .name = 'default::TestEmbeddingModel' ) select model.x """, ['8191'], )
, explicit_modules=True) await self.assert_query_result( r
test_edgeql_migration_ai_10
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def get_migrations(self): res = await self.con.query( ''' select schema::Migration { id, name, script, sdl, parents: {name, id}, generated_by } ''' ) if not res: return [] children = {m.parents[0].id: m for m in res if m.parents} root = [m for m in res if not m.parents][0] sorted_migs = [] while root: sorted_migs.append(root) root = children.get(root.id) return sorted_migs
select schema::Migration { id, name, script, sdl, parents: {name, id}, generated_by }
get_migrations
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_rewrite_01(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') # Split one migration up into several await self.migrate(r""" type A; type B; type C; type D; """) # Try a bunch of different ways to do it! await self.con.execute(r""" start migration rewrite; start migration to { module default { type A; } }; populate migration; commit migration; start migration to { module default { type A; type B; } }; CREATE type B; commit migration; create migration { create type C; }; CREATE TYPE D; commit migration rewrite; """) await self.assert_migration_history([ { 'script': 'CREATE TYPE default::A;', 'sdl': ( 'module default {\n' ' type A;\n' '};' ), 'generated_by': None, }, { 'script': 'CREATE TYPE B;', 'sdl': ( 'module default {\n' ' type A;\n' ' type B;\n' '};' ), 'generated_by': None, }, { 'script': 'create type C;', 'sdl': ( 'module default {\n' ' type A;\n' ' type B;\n' ' type C;\n' '};' ), 'generated_by': None, }, { 'script': ( 'SET generated_by ' ':= (schema::MigrationGeneratedBy.DDLStatement);\n' 'CREATE TYPE D;' ), 'sdl': ( 'module default {\n' ' type A;\n' ' type B;\n' ' type C;\n' ' type D;\n' '};' ), 'generated_by': 'DDLStatement', }, ])
) # Split one migration up into several await self.migrate(r
test_edgeql_migration_rewrite_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_rewrite_02(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') # Simulate a potential migration squashing flow from the CLI, # where we generate a script using start migration and then apply it # later. await self.con.execute(r""" create type Foo; create type Tgt; alter type Foo { create link tgt -> Tgt; }; """) await self.con.execute(r""" start migration rewrite; """) await self.con.execute(r""" start migration to committed schema; """) await self.con.execute(r""" populate migration; """) res = json.loads(await self.con.query_json(r""" describe current migration as json; """)) await self.con.execute(r""" commit migration; """) await self.con.execute(r""" abort migration rewrite; """) self.assertTrue(res[0]['complete']) commands = '\n'.join(res[0]['confirmed']) script = textwrap.dedent('''\ start migration rewrite; create migration { %s }; commit migration rewrite; ''') % textwrap.indent(commands, ' ' * 4) await self.con.execute(script) await self.assert_migration_history([ { 'script': commands, 'sdl': ( 'module default {\n' ' type Foo {\n' ' link tgt: default::Tgt;\n' ' };\n' ' type Tgt;\n' '};' ), } ])
) # Simulate a potential migration squashing flow from the CLI, # where we generate a script using start migration and then apply it # later. await self.con.execute(r
test_edgeql_migration_rewrite_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_rewrite_03(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') # Test rolling back to a savepoint after a commit failure await self.con.execute(r""" create type A; create type B; """) await self.con.execute(r""" start migration rewrite; """) await self.con.execute(r""" declare savepoint s0; """) await self.con.execute(r""" create type B; """) await self.con.execute(r""" declare savepoint s1; """) with self.assertRaisesRegex( edgedb.QueryError, r"does not match"): await self.con.execute(r""" commit migration rewrite; """) # Rollback and try again await self.con.execute(r""" rollback to savepoint s1; """) await self.con.execute(r""" create type A; """) await self.con.execute(r""" commit migration rewrite """) gby = ( 'SET generated_by := (schema::MigrationGeneratedBy.DDLStatement);' ) await self.assert_migration_history([ { 'script': gby + '\n' + 'CREATE TYPE B;', 'sdl': ( 'module default {\n' ' type B;\n' '};' ), }, { 'script': gby + '\n' + 'CREATE TYPE A;', 'sdl': ( 'module default {\n' ' type A;\n' ' type B;\n' '};' ), }, ])
) # Test rolling back to a savepoint after a commit failure await self.con.execute(r
test_edgeql_migration_rewrite_03
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_rewrite_05(self): # Test ABORT MIGRATION REWRITE await self.con.execute(r""" create type A; create type B; """) await self.con.execute(r""" start migration rewrite; """) with self.assertRaisesRegex( edgedb.QueryError, r"does not match"): await self.con.execute(r""" commit migration rewrite; """) await self.con.execute(r""" abort migration rewrite; """)
) await self.con.execute(r
test_edgeql_migration_rewrite_05
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_rewrite_06(self): await self.con.execute(''' CONFIGURE SESSION SET store_migration_sdl := cfg::StoreMigrationSDL.AlwaysStore; ''') # Test doing the interactive migration flow await self.con.execute(r""" create type A; create type B; """) await self.con.execute(r""" start migration rewrite; """) await self.start_migration(r""" type A; type B; """, module='default') await self.fast_forward_describe_migration() await self.con.execute(r""" commit migration rewrite; """) await self.assert_migration_history([ { 'script': 'CREATE TYPE default::A;\nCREATE TYPE default::B;', 'sdl': ( 'module default {\n' ' type A;\n' ' type B;\n' '};' ), }, ])
) # Test doing the interactive migration flow await self.con.execute(r
test_edgeql_migration_rewrite_06
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_dt_realativedelta_01(self): await self.assert_query_result( r"SELECT <cal::relative_duration>'1 year 2 seconds'", ['P1YT2S'], [edgedb.RelativeDuration(months=12, microseconds=2_000_000)], ) await self.assert_query_result( r"SELECT <str><cal::relative_duration>'1 year 2 seconds'", ['P1YT2S'], ) await self.assert_query_result( r"SELECT <json><cal::relative_duration><json>'1 year 2 seconds'", ['P1YT2S'], ['"P1YT2S"'], ) await self.assert_query_result( r""" WITH dt := <datetime>'2000-01-01T00:00:00Z', rd := <cal::relative_duration>'3 years 2 months 14 days' SELECT (dt + rd, rd + dt, dt - rd) """, [( '2003-03-15T00:00:00+00:00', '2003-03-15T00:00:00+00:00', '1996-10-18T00:00:00+00:00', )], ) await self.assert_query_result( r""" WITH dt := <cal::local_datetime>'2000-01-01T00:00:00', rd := <cal::relative_duration>'3 years 2 months 14 days' SELECT (dt + rd, rd + dt, dt - rd) """, [( '2003-03-15T00:00:00', '2003-03-15T00:00:00', '1996-10-18T00:00:00', )], ) await self.assert_query_result( r""" WITH d := <cal::local_date>'2000-01-01', rd := <cal::relative_duration>'3 years 2 months 14 days' SELECT (d + rd, rd + d, d - rd) """, [('2003-03-15T00:00:00', '2003-03-15T00:00:00', '1996-10-18T00:00:00')], ) await self.assert_query_result( r""" WITH t := <cal::local_time>'00:00:00', rd := <cal::relative_duration>'3h2m1s' SELECT (t + rd, rd + t, t - rd) """, [('03:02:01', '03:02:01', '20:57:59')], ) await self.assert_query_result( r""" WITH rd := <cal::relative_duration>'3h2m1s' SELECT ( rd = rd, rd ?= rd, rd != rd, rd ?!= rd, rd > rd, rd >= rd, rd < rd, rd <= rd, rd + rd, rd - rd, -rd, ) """, [( True, True, False, False, False, True, False, True, 'PT6H4M2S', 'PT0S', 'PT-3H-2M-1S', )], [( True, True, False, False, False, True, False, True, edgedb.RelativeDuration(microseconds=21_842_000_000), edgedb.RelativeDuration(), edgedb.RelativeDuration(microseconds=-10_921_000_000), )], ) await self.assert_query_result( r" SELECT <json><cal::relative_duration>'3y2h' ", ['P3YT2H'], ['"P3YT2H"'], ) await self.assert_query_result( r" SELECT <cal::relative_duration><json>'P3YT2H' ", ['P3YT2H'], [edgedb.RelativeDuration(months=36, microseconds=7200000000)], ) await self.assert_query_result( r""" SELECT ( to_str( <cal::relative_duration>'3y' + <cal::relative_duration>'1h' ), to_str(<cal::relative_duration>'3y1h', 'YYYY"y"HH24"h"'), ) """, [['P3YT1H', '0003y01h']], ) await self.assert_query_result( r""" SELECT cal::to_relative_duration( years := 1, months := 2, days := 3, hours := 4, minutes := 5, seconds := 6, microseconds := 7, ) """, ['P1Y2M3DT4H5M6.000007S'], [edgedb.RelativeDuration(months=14, days=3, microseconds=14706000007)], ) await self.assert_query_result( r""" WITH x := <cal::relative_duration>'1y', y := <cal::relative_duration>'5y', SELECT ( max({x, y}), min({x, y}), ) """, [['P5Y', 'P1Y']], [( edgedb.RelativeDuration(months=60), edgedb.RelativeDuration(months=12), )] ) await self.assert_query_result( r""" WITH rd := <cal::relative_duration>'1s', d := <duration>'5s', SELECT (<duration>rd, <cal::relative_duration>d) """, [['PT1S', 'PT5S']], [( timedelta(seconds=1), edgedb.RelativeDuration(microseconds=5_000_000), )] ) with self.assertRaisesRegex( edgedb.InvalidValueError, "invalid value for scalar type 'std::duration'"): await self.con.query(r""" WITH rd := <cal::relative_duration>'1y' SELECT <duration>rd """)
, [( '2003-03-15T00:00:00+00:00', '2003-03-15T00:00:00+00:00', '1996-10-18T00:00:00+00:00', )], ) await self.assert_query_result( r
test_edgeql_dt_realativedelta_01
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_realativedelta_02(self): await self.assert_query_result( r"SELECT <str><cal::date_duration>'1 year 2 days'", ['P1Y2D'], ) await self.assert_query_result( r"SELECT <json><cal::date_duration><json>'1 year 2 days'", ['P1Y2D'], ['"P1Y2D"'], ) await self.assert_query_result( r"SELECT <str><cal::date_duration>'0 days'", ['P0D'], ) await self.assert_query_result( r"SELECT <json><cal::date_duration>'0 days'", ['P0D'], ['"P0D"'], ) await self.assert_query_result( r"SELECT <json><cal::date_duration>'5 months -150 days'", ['P5M-150D'], ['"P5M-150D"'], ) await self.assert_query_result( r""" WITH dt := <datetime>'2000-01-01T00:00:00Z', rd := <cal::date_duration>'3 years 2 months 14 days' SELECT (dt + rd, rd + dt, dt - rd) """, [( '2003-03-15T00:00:00+00:00', '2003-03-15T00:00:00+00:00', '1996-10-18T00:00:00+00:00', )], ) await self.assert_query_result( r""" WITH dt := <cal::local_datetime>'2000-01-01T00:00:00', rd := <cal::date_duration>'3 years 2 months 14 days' SELECT (dt + rd, rd + dt, dt - rd) """, [( '2003-03-15T00:00:00', '2003-03-15T00:00:00', '1996-10-18T00:00:00', )], ) await self.assert_query_result( r""" WITH d := <cal::local_date>'2000-01-01', rd := <cal::date_duration>'3 years 2 months 14 days' SELECT (d + rd, rd + d, d - rd) """, [('2003-03-15', '2003-03-15', '1996-10-18')], ) await self.assert_query_result( r" SELECT <json><cal::date_duration>'3y2d' ", ['P3Y2D'], ['"P3Y2D"'], ) await self.assert_query_result( r""" SELECT ( to_str( <cal::date_duration>'3y' + <cal::date_duration>'1d' ), to_str(<cal::date_duration>'3y1d', 'YYYY"y"DD"d"'), ) """, [['P3Y1D', '0003y01d']], ) await self.assert_query_result( r""" SELECT <str>cal::to_date_duration( years := 1, months := 2, days := 3, ) """, ['P1Y2M3D'], ) await self.assert_query_result( r""" WITH x := <cal::date_duration>'1y', y := <cal::date_duration>'5y', SELECT ( <str>max({x, y}), <str>min({x, y}), ) """, [['P5Y', 'P1Y']], ) with self.assertRaisesRegex( edgedb.InvalidValueError, "invalid input syntax for type std::cal::date_duration: '1s'"): async with self.con.transaction(): await self.con.query(r""" SELECT <str><cal::date_duration>'1s' """) with self.assertRaisesRegex( edgedb.InvalidValueError, "invalid input syntax for type std::cal::date_duration: '1s'"): async with self.con.transaction(): await self.con.query(r""" SELECT <str><cal::date_duration><json>'1s' """)
, [( '2003-03-15T00:00:00+00:00', '2003-03-15T00:00:00+00:00', '1996-10-18T00:00:00+00:00', )], ) await self.assert_query_result( r
test_edgeql_dt_realativedelta_02
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_datetime_03(self): await self.assert_query_result( r'''SELECT <tuple<str,datetime>>( 'foo', '2017-10-10T00:00:00+00'); ''', [['foo', '2017-10-10T00:00:00+00:00']], ) await self.assert_query_result( r''' SELECT (<tuple<str,datetime>>( 'foo', '2017-10-10T00:00:00+00')).1 + <duration>'744 hours'; ''', ['2017-11-10T00:00:00+00:00'], )
, [['foo', '2017-10-10T00:00:00+00:00']], ) await self.assert_query_result( r
test_edgeql_dt_datetime_03
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_07_datetime_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <datetime>'9999-12-31T00:00:00Z' + <duration>'30 hours' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <datetime>'0001-01-01T00:00:00Z' - <duration>'30 hours' """ )
SELECT <datetime>'9999-12-31T00:00:00Z' + <duration>'30 hours'
test_edgeql_dt_duration_07_datetime_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_08_local_datetime_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_datetime>'9999-12-31T00:00:00' + <duration>'30 hours' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_datetime>'0001-01-01T00:00:00' - <duration>'30 hours' """ )
SELECT <cal::local_datetime>'9999-12-31T00:00:00' + <duration>'30 hours'
test_edgeql_dt_duration_08_local_datetime_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_09_local_date_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_date>'9999-12-31' + <duration>'30 hours' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_date>'0001-01-01' - <duration>'30 hours' """ )
SELECT <cal::local_date>'9999-12-31' + <duration>'30 hours'
test_edgeql_dt_duration_09_local_date_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_10_datetime_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <datetime>'9999-12-31T00:00:00Z' + <cal::relative_duration>'1 week' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <datetime>'0001-01-01T00:00:00Z' - <cal::relative_duration>'1 week' """ )
SELECT <datetime>'9999-12-31T00:00:00Z' + <cal::relative_duration>'1 week'
test_edgeql_dt_duration_10_datetime_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_11_local_datetime_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_datetime>'9999-12-31T00:00:00' + <cal::relative_duration>'1 week' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_datetime>'0001-01-01T00:00:00' - <cal::relative_duration>'1 week' """ )
SELECT <cal::local_datetime>'9999-12-31T00:00:00' + <cal::relative_duration>'1 week'
test_edgeql_dt_duration_11_local_datetime_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_duration_12_local_date_range(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_date>'9999-12-31' + <cal::relative_duration>'30 hours' """ ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, 'value out of range', ): await self.con.execute( """ SELECT <cal::local_date>'0001-01-01' - <cal::relative_duration>'30 hours' """ )
SELECT <cal::local_date>'9999-12-31' + <cal::relative_duration>'30 hours'
test_edgeql_dt_duration_12_local_date_range
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_local_datetime_01(self): await self.assert_query_result( r''' SELECT <cal::local_datetime>'2017-10-10T13:11' + <duration>'24 hours'; ''', ['2017-10-11T13:11:00'], ) await self.assert_query_result( r''' SELECT <duration>'24 hours' + <cal::local_datetime>'2017-10-10T13:11'; ''', ['2017-10-11T13:11:00'], ) await self.assert_query_result( r''' SELECT <cal::local_datetime>'2017-10-10T13:11' - <duration>'24 hours'; ''', ['2017-10-09T13:11:00'], )
, ['2017-10-11T13:11:00'], ) await self.assert_query_result( r
test_edgeql_dt_local_datetime_01
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_local_datetime_03(self): # Corner case which interprets month in a fuzzy way. await self.assert_query_result( r''' with dur := <cal::relative_duration>'1 month' select <cal::local_datetime>'2021-01-31T00:00:00' + dur; ''', ['2021-02-28T00:00:00'], ) # + not always associative await self.assert_query_result( r''' with dur := <cal::relative_duration>'1 month', date := <cal::local_datetime>'2021-01-31T00:00:00', select date + (dur + dur) = (date + dur) + dur; ''', [False], ) # - not always inverse of plus await self.assert_query_result( r''' with dur := <cal::relative_duration>'1 month', date := <cal::local_datetime>'2021-01-31T00:00:00', select date + dur - dur = date; ''', [False], ) # - not always inverse of plus await self.assert_query_result( r''' with m1 := <cal::relative_duration>'1 month', m11 := <cal::relative_duration>'11 month', y1 := <cal::relative_duration>'1 year', date := <cal::local_datetime>'2021-01-31T00:00:00', select ( # duration alone y1 = m1 + m11, # date + duration date + y1 = date + m1 + m11, ); ''', [[True, False]], )
, ['2021-02-28T00:00:00'], ) # + not always associative await self.assert_query_result( r
test_edgeql_dt_local_datetime_03
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_local_date_03(self): # Corner case which interprets month in a fuzzy way. await self.assert_query_result( r''' with dur := <cal::date_duration>'1 month' select <cal::local_date>'2021-01-31' + dur; ''', ['2021-02-28'], ) # + not always associative await self.assert_query_result( r''' with dur := <cal::date_duration>'1 month', date := <cal::local_date>'2021-01-31', select date + (dur + dur) = (date + dur) + dur; ''', [False], ) # - not always inverse of plus await self.assert_query_result( r''' with dur := <cal::date_duration>'1 month', date := <cal::local_date>'2021-01-31', select date + dur - dur = date; ''', [False], ) # - not always inverse of plus await self.assert_query_result( r''' with m1 := <cal::date_duration>'1 month', m11 := <cal::date_duration>'11 month', y1 := <cal::date_duration>'1 year', date := <cal::local_date>'2021-01-31', select ( # duration alone y1 = m1 + m11, # date + duration date + y1 = date + m1 + m11, ); ''', [[True, False]], )
, ['2021-02-28'], ) # + not always associative await self.assert_query_result( r
test_edgeql_dt_local_date_03
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_dt_enum_01(self): await self.assert_query_result( r''' SELECT <enum_t>'foo' = <enum_t>'bar' ''', [ False ], ) await self.assert_query_result( r''' SELECT <enum_t>'foo' = <enum_t>'foo' ''', [ True ], ) await self.assert_query_result( r''' SELECT <enum_t>'foo' < <enum_t>'bar' ''', [ True ], ) with self.assertRaisesRegex( edgedb.InvalidValueError, 'invalid input value for enum \'default::enum_t\': "bad"'): await self.con.execute( 'SELECT <enum_t>"bad";' )
, [ False ], ) await self.assert_query_result( r
test_edgeql_dt_enum_01
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_staeval_duration_01(self): valid = [ ' 100 ', '123', '-123', ' 20 mins 1hr ', ' 20 mins -1hr ', ' 20us 1h 20 ', ' -20us 1h 20 ', ' -20US 1H 20 ', '1 hour 20 minutes 30 seconds 40 milliseconds 50 microseconds', '1 hour 20 minutes +30seconds 40 milliseconds -50microseconds', '1 houR 20 minutes 30SECOND 40 milliseconds 50 us', ' 20 us 1H 20 minutes ', '-1h', '100h', ' 12:12:12.2131 ', '-12:12:12.21313', '-12:12:12.213134', '-12:12:12.2131341', '-12:12:12.2131341111111', '-12:12:12.2131315111111', '-12:12:12.2131316111111', '-12:12:12.2131314511111', '-0:12:12.2131', '12:12', '-12:12', '-12:1:1', '+12:1:1', '-12:1:1.1234', '1211:59:59.9999', '-12:', '0', '00:00:00', '00:00:10.9', '00:00:10.09', '00:00:10.009', '00:00:10.0009', ] invalid = [ 'blah', '!', '-', ' 20 us 1H 20 30 minutes ', ' 12:12:121.2131 ', ' 12:60:21.2131 ', ' 20us 20 1h ', ' 20us $ 20 1h ', '1 houR 20 minutes 30SECOND 40 milliseconds 50 uss', ] v = await self.con.query_single( ''' SELECT <array<duration>><array<str>>$0 ''', valid ) vs = await self.con.query_single( ''' SELECT <array<str>><array<duration>><array<str>>$0 ''', valid ) for text, value, svalue in zip(valid, v, vs): ref_value = int(value / timedelta(microseconds=1)) try: parsed = statypes.Duration(text) except Exception: raise AssertionError( f'could not parse a valid std::duration: {text!r}') self.assertEqual( ref_value, parsed.to_microseconds(), text) self.assertEqual( svalue, parsed.to_iso8601(), text) self.assertEqual( statypes.Duration.from_iso8601(svalue).to_microseconds(), parsed.to_microseconds(), text) self.assertEqual( statypes.Duration(svalue).to_microseconds(), parsed.to_microseconds(), text) for text in invalid: async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'(invalid input syntax)|(interval field value out)'): await self.con.query_single( '''SELECT <duration><str>$0''', text ) with self.assertRaises( (errors.InvalidValueError, errors.NumericOutOfRangeError)): statypes.Duration(text)
SELECT <array<duration>><array<str>>$0 ''', valid ) vs = await self.con.query_single(
test_edgeql_staeval_duration_01
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
async def test_edgeql_staeval_memory_01(self): valid = [ '0', '0B', '123KiB', '11MiB', '0PiB', '1PiB', '111111GiB', '123B', '2219486241101731KiB', ] invalid = [ '12kB', '22KB', '-1B', '-1', '+1', '+12TiB', '123TIB', ] v = await self.con.query_single( ''' SELECT <array<int64>><array<cfg::memory>><array<str>>$0 ''', valid ) vs = await self.con.query_single( ''' SELECT <array<str>><array<cfg::memory>><array<str>>$0 ''', valid ) for text, ref_value, svalue in zip(valid, v, vs): try: parsed = statypes.ConfigMemory(text) except Exception: raise AssertionError( f'could not parse a valid cfg::memory: {text!r}') self.assertEqual( ref_value, parsed.to_nbytes(), text) self.assertEqual( svalue, parsed.to_str(), text) self.assertEqual( statypes.ConfigMemory(svalue).to_nbytes(), parsed.to_nbytes(), text) for text in invalid: async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'(unsupported memory size)|(unable to parse memory)'): await self.con.query_single( '''SELECT <int64><cfg::memory><str>$0''', text ) with self.assertRaises(errors.InvalidValueError): statypes.ConfigMemory(text)
SELECT <array<int64>><array<cfg::memory>><array<str>>$0 ''', valid ) vs = await self.con.query_single(
test_edgeql_staeval_memory_01
python
geldata/gel
tests/test_edgeql_datatypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_datatypes.py
Apache-2.0
def test_edgeql_ir_volatility_inference_00(self): """ SELECT Card % OK % Stable """
SELECT Card % OK % Stable
test_edgeql_ir_volatility_inference_00
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_01(self): """ WITH foo := random() SELECT foo % OK % Volatile """
WITH foo := random() SELECT foo % OK % Volatile
test_edgeql_ir_volatility_inference_01
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_02(self): """ SELECT Card FILTER random() > 0.9 % OK % Volatile """
SELECT Card FILTER random() > 0.9 % OK % Volatile
test_edgeql_ir_volatility_inference_02
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_03(self): """ SELECT Card ORDER BY random() % OK % Volatile """
SELECT Card ORDER BY random() % OK % Volatile
test_edgeql_ir_volatility_inference_03
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_04(self): """ SELECT Card LIMIT <int64>random() % OK % Volatile """
SELECT Card LIMIT <int64>random() % OK % Volatile
test_edgeql_ir_volatility_inference_04
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_05(self): """ SELECT Card OFFSET <int64>random() % OK % Volatile """
SELECT Card OFFSET <int64>random() % OK % Volatile
test_edgeql_ir_volatility_inference_05
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_06(self): """ INSERT Card { name := 'foo', element := 'fire', cost := 1, } % OK % Modifying """
INSERT Card { name := 'foo', element := 'fire', cost := 1, } % OK % Modifying
test_edgeql_ir_volatility_inference_06
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_07(self): """ UPDATE Card SET { name := 'foo', } % OK % Modifying """
UPDATE Card SET { name := 'foo', } % OK % Modifying
test_edgeql_ir_volatility_inference_07
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_08(self): """ DELETE Card % OK % Modifying """
DELETE Card % OK % Modifying
test_edgeql_ir_volatility_inference_08
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_09(self): """ with X := 1 select X % OK % Immutable """
with X := 1 select X % OK % Immutable
test_edgeql_ir_volatility_inference_09
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_10(self): """ with X := User select X % OK % Stable """
with X := User select X % OK % Stable
test_edgeql_ir_volatility_inference_10
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_11(self): """ with X := random() select X % OK % Volatile """
with X := random() select X % OK % Volatile
test_edgeql_ir_volatility_inference_11
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_12(self): """ select AliasOne % OK % Immutable """
select AliasOne % OK % Immutable
test_edgeql_ir_volatility_inference_12
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_13(self): """ select global GlobalOne % OK % Stable """
select global GlobalOne % OK % Stable
test_edgeql_ir_volatility_inference_13
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_14(self): """ select AirCard % OK % Stable """
select AirCard % OK % Stable
test_edgeql_ir_volatility_inference_14
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_15(self): """ select global HighestCost % OK % Stable """
select global HighestCost % OK % Stable
test_edgeql_ir_volatility_inference_15
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
def test_edgeql_ir_volatility_inference_16(self): """ select global CardsWithText % OK % Stable """
select global CardsWithText % OK % Stable
test_edgeql_ir_volatility_inference_16
python
geldata/gel
tests/test_edgeql_ir_volatility_inference.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_volatility_inference.py
Apache-2.0
async def test_session_set_command_06(self): # Check that nested WITH blocks work correctly, with and # without DETACHED. await self.assert_query_result( """ WITH MODULE foo SELECT ( Entity.name, fuz::Entity.name ); """, [['entity', 'fuzentity']], ) await self.assert_query_result( """ WITH MODULE foo SELECT ( Entity.name, (WITH MODULE fuz SELECT Entity.name) ); """, [['entity', 'fuzentity']], ) await self.assert_query_result( """ WITH MODULE foo SELECT ( Entity.name, (WITH MODULE fuz SELECT DETACHED Entity.name) ); """, [['entity', 'fuzentity']], )
WITH MODULE foo SELECT ( Entity.name, fuz::Entity.name ); """, [['entity', 'fuzentity']], ) await self.assert_query_result(
test_session_set_command_06
python
geldata/gel
tests/test_session.py
https://github.com/geldata/gel/blob/master/tests/test_session.py
Apache-2.0
async def test_session_ddl_default_module_01(self): await self.con.execute('RESET ALIAS *') tx = self.con.transaction() await tx.start() try: await self.con.execute(''' ALTER TYPE User { # Test that UserOneToOneAlias doesn't block the alter. DROP PROPERTY name_len; } ''') await self.con.execute(''' ALTER TYPE User { CREATE PROPERTY aaa := len( 'yes' IF __source__ IS User ELSE 'no'); CREATE PROPERTY name_upper := str_upper(.name); } ''') await self.assert_query_result( """ SELECT User {name, aaa, name_upper}; """, [{ 'name': 'user', 'aaa': 3, 'name_upper': 'USER', }] ) finally: await tx.rollback()
) await self.con.execute(
test_session_ddl_default_module_01
python
geldata/gel
tests/test_session.py
https://github.com/geldata/gel/blob/master/tests/test_session.py
Apache-2.0
async def test_session_warnings_01(self): # N.B: The testbase warning system always raises async with self.assertRaisesRegexTx( edgedb.QueryError, "Test warning please ignore" ): await self.con.query(''' select _warn_on_call() ''') async with self.assertRaisesRegexTx( edgedb.QueryError, "Test warning please ignore" ): await self.con.execute(''' create function asdf() -> int64 using (_warn_on_call()) ''') async with self.assertRaisesRegexTx( edgedb.QueryError, "Test warning please ignore" ): await self.con.execute(''' start migration to { module default { function asdf() -> int64 using (_warn_on_call()) } } ''')
) async with self.assertRaisesRegexTx( edgedb.QueryError, "Test warning please ignore" ): await self.con.execute(
test_session_warnings_01
python
geldata/gel
tests/test_session.py
https://github.com/geldata/gel/blob/master/tests/test_session.py
Apache-2.0
async def test_edgeql_vector_cast_01(self): # Basic casts to and from json. Also a cast into an # array<float32>. await self.assert_query_result( ''' select <json><ext::pgvector::vector>[1, 2, 3.5]; ''', [[1, 2, 3.5]], json_only=True, ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector> to_json('[1.5, 2, 3]'); ''', [[1.5, 2, 3]], )
select <json><ext::pgvector::vector>[1, 2, 3.5]; ''', [[1, 2, 3.5]], json_only=True, ) await self.assert_query_result(
test_edgeql_vector_cast_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_02(self): # Basic casts from json. await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector>to_json(( select _ := Basic.p_str order by _ )) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector>( select _ := Basic.p_json order by _ ) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], )
select <array<float32>><ext::pgvector::vector>to_json(( select _ := Basic.p_str order by _ )) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], ) await self.assert_query_result(
test_edgeql_vector_cast_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_03(self): # Casts from numeric array expressions. await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<int16>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<int32>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<int64>>[1.0, 2.0, 3.0]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<float32>>[1.5, 2, 3]; ''', [[1.5, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<float64>>[1, 2, 3]; ''', [[1, 2, 3]], )
select <array<float32>> <ext::pgvector::vector><array<int16>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result(
test_edgeql_vector_cast_03
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_04(self): # Casts from numeric array expressions. res = [0, 3, 4, 7] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_int16 order by Raw.p_int16 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_int32 order by Raw.p_int32 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_int64 order by Raw.p_int64 ); ''', [res], )
select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_int16 order by Raw.p_int16 ); ''', [res], ) await self.assert_query_result(
test_edgeql_vector_cast_04
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_05(self): # Casts from numeric array expressions. res = [0, 3, 4.25, 6.75] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_float32 order by Raw.p_float32 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.val order by Raw.val ); ''', [res], )
select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_float32 order by Raw.p_float32 ); ''', [res], ) await self.assert_query_result(
test_edgeql_vector_cast_05
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_06(self): # Casts from literal numeric arrays. await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector> [<int16>1, <int16>2, <int16>3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector> [<int32>1, <int32>2, <int32>3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector>[1.5, 2, 3]; ''', [[1.5, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::vector> [<float32>1.5, <float32>2, <float32>3]; ''', [[1.5, 2, 3]], )
select <array<float32>><ext::pgvector::vector>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result(
test_edgeql_vector_cast_06
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_08(self): # Casts from arrays of derived types. await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<myf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector><array<deepf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg(<myf64>{1, 2.3, 4.5}); ''', [[1, 2.3, 4.5]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg(<deepf64>{1, 2.3, 4.5}); ''', [[1, 2.3, 4.5]], )
select <array<float32>> <ext::pgvector::vector><array<myf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], ) await self.assert_query_result(
test_edgeql_vector_cast_08
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_09(self): # Casts from arrays of derived types. res = [0, 3, 4.25, 6.75] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_myf64 order by Raw.p_myf64 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_deepf64 order by Raw.p_deepf64 ); ''', [res], )
select <array<float32>> <ext::pgvector::vector>array_agg( Raw.p_myf64 order by Raw.p_myf64 ); ''', [res], ) await self.assert_query_result(
test_edgeql_vector_cast_09
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_cast_10(self): # Arrays of vectors. await self.assert_query_result( ''' with module ext::pgvector select [ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, ) # Arrays of vectors. await self.assert_query_result( ''' with module ext::pgvector select <json>[ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, )
with module ext::pgvector select [ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, ) # Arrays of vectors. await self.assert_query_result(
test_edgeql_vector_cast_10
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_op_01(self): # Comparison operators. await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2, 3] = <ext::pgvector::vector>[0, 1, 1]; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2, 3] != <ext::pgvector::vector>[0, 1, 1]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2, 3] ?= <ext::pgvector::vector>{}; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2, 3] ?!= <ext::pgvector::vector>{}; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::vector>{} ?= <ext::pgvector::vector>{}; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2] < <ext::pgvector::vector>[2, 3]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2] <= <ext::pgvector::vector>[2, 3]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2] > <ext::pgvector::vector>[2, 3]; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::vector>[1, 2] >= <ext::pgvector::vector>[2, 3]; ''', [False], )
select <ext::pgvector::vector>[1, 2, 3] = <ext::pgvector::vector>[0, 1, 1]; ''', [False], ) await self.assert_query_result(
test_edgeql_vector_op_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_op_02(self): await self.assert_query_result( ''' with module ext::pgvector select <vector>to_json('[3, 0]') in { <vector>to_json('[1, 2]'), <vector>to_json('[3, 4]'), }; ''', [False], ) await self.assert_query_result( ''' with module ext::pgvector select <vector>to_json('[3, 0]') not in { <vector>to_json('[1, 2]'), <vector>to_json('[3, 4]'), }; ''', [True], )
with module ext::pgvector select <vector>to_json('[3, 0]') in { <vector>to_json('[1, 2]'), <vector>to_json('[3, 4]'), }; ''', [False], ) await self.assert_query_result(
test_edgeql_vector_op_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_01(self): await self.assert_query_result( ''' with module ext::pgvector select len( <vector>to_json('[1.2, 3.4, 5, 6]'), ); ''', [4], ) await self.assert_query_result( ''' with module ext::pgvector select len(default::IVFFlat_vec_L2.vec) limit 1; ''', [3], )
with module ext::pgvector select len( <vector>to_json('[1.2, 3.4, 5, 6]'), ); ''', [4], ) await self.assert_query_result(
test_edgeql_vector_func_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_02(self): await self.assert_query_result( ''' with module ext::pgvector select euclidean_distance( <vector>[3, 4], <vector>[0, 0], ); ''', [5], ) await self.assert_query_result( ''' with module ext::pgvector select euclidean_distance( default::IVFFlat_vec_L2.vec, <vector>[0, 1, 0], ); ''', {2.299999952316284, 10.159335266542493, 11.48694872607437}, )
with module ext::pgvector select euclidean_distance( <vector>[3, 4], <vector>[0, 0], ); ''', [5], ) await self.assert_query_result(
test_edgeql_vector_func_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_03(self): await self.assert_query_result( ''' with module ext::pgvector select euclidean_norm(<vector>[3, 4]); ''', [5], ) await self.assert_query_result( ''' with module ext::pgvector select euclidean_norm(default::IVFFlat_vec_L2.vec); ''', {2.5079872331917934, 10.208432276239787, 12.014573942925704}, )
with module ext::pgvector select euclidean_norm(<vector>[3, 4]); ''', [5], ) await self.assert_query_result(
test_edgeql_vector_func_03
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_04(self): await self.assert_query_result( ''' with module ext::pgvector select neg_inner_product( <vector>[1, 2], <vector>[3, 4], ); ''', [-11], ) await self.assert_query_result( ''' with module ext::pgvector select neg_inner_product( default::IVFFlat_vec_IP.vec, <vector>[3, 4, 1], ); ''', {-6.299999952316284, -17.109999656677246, -49.19999885559082}, )
with module ext::pgvector select neg_inner_product( <vector>[1, 2], <vector>[3, 4], ); ''', [-11], ) await self.assert_query_result(
test_edgeql_vector_func_04
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_05(self): await self.assert_query_result( ''' with module ext::pgvector select cosine_distance( <vector>[3, 0], <vector>[3, 4], ); ''', [0.4], ) await self.assert_query_result( ''' with module ext::pgvector select cosine_distance( default::IVFFlat_vec_Cosine.vec, <vector>[3, 4, 1], ); ''', {0.5073612713543951, 0.6712965405380352, 0.19689922670600213}, )
with module ext::pgvector select cosine_distance( <vector>[3, 0], <vector>[3, 4], ); ''', [0.4], ) await self.assert_query_result(
test_edgeql_vector_func_05
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_06(self): await self.assert_query_result( ''' with module ext::pgvector select <array<float32>> mean({ <vector>[3, 0], <vector>[0, 4], }); ''', [[1.5, 2]], ) await self.assert_query_result( ''' with module ext::pgvector select <array<float32>> mean(default::IVFFlat_vec_L2.vec); ''', [[1.8333334, 2.8999999, 7.103333]], )
with module ext::pgvector select <array<float32>> mean({ <vector>[3, 0], <vector>[0, 4], }); ''', [[1.5, 2]], ) await self.assert_query_result(
test_edgeql_vector_func_06
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_func_08(self): async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <vector>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, 3, 0) """) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <vector>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, -2, 1) """) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <vector>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, 20, 2) """)
) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r
test_edgeql_vector_func_08
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_insert_01(self): # Test assignment casts res = [0, 3, 4] async with self._run_and_rollback(): await self.con.execute(r""" insert IVFFlat_vec_L2 { vec := array_agg( Raw.p_int16 order by Raw.p_int16 )[:3] } """) await self.assert_query_result( ''' with res := <array<float32>>$res select <array<float32>>( select IVFFlat_vec_L2 filter .vec = <ext::pgvector::vector>res ).vec ''', [res], variables=dict(res=res), ) async with self._run_and_rollback(): await self.con.execute(r""" insert IVFFlat_vec_L2 { vec := array_agg( Raw.p_int32 order by Raw.p_int32 )[:3] } """) await self.assert_query_result( ''' with res := <array<float32>>$res select <array<float32>>( select IVFFlat_vec_L2 filter .vec = <ext::pgvector::vector>res ).vec ''', [res], variables=dict(res=res), ) async with self._run_and_rollback(): await self.con.execute(r""" insert IVFFlat_vec_L2 { vec := array_agg( Raw.p_int64 order by Raw.p_int64 )[:3] } """) await self.assert_query_result( ''' with res := <array<float32>>$res select <array<float32>>( select IVFFlat_vec_L2 filter .vec = <ext::pgvector::vector>res ).vec ''', [res], variables=dict(res=res), )
) await self.assert_query_result(
test_edgeql_vector_insert_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_insert_02(self): # Test assignment casts res = [0, 3, 4.25] async with self._run_and_rollback(): await self.con.execute(r""" insert IVFFlat_vec_L2 { vec := array_agg( Raw.p_float32 order by Raw.p_float32 )[:3] } """) await self.assert_query_result( ''' with res := <array<float32>>$res select <array<float32>>( select IVFFlat_vec_L2 filter .vec = <ext::pgvector::vector>res ).vec ''', [res], variables=dict(res=res), ) async with self._run_and_rollback(): await self.con.execute(r""" insert IVFFlat_vec_L2 { vec := array_agg( Raw.val order by Raw.val )[:3] } """) await self.assert_query_result( ''' with res := <array<float32>>$res select <array<float32>>( select IVFFlat_vec_L2 filter .vec = <ext::pgvector::vector>res ).vec ''', [res], variables=dict(res=res), )
) await self.assert_query_result(
test_edgeql_vector_insert_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_constraint_01(self): async with self._run_and_rollback(): await self.con.execute(r""" insert Con { vec := [1, 1, 2] } """) async with self.assertRaisesRegexTx( edgedb.errors.ConstraintViolationError, '' ): await self.con.execute(r""" insert Con { vec := [1, 20, 1] } """)
) async with self.assertRaisesRegexTx( edgedb.errors.ConstraintViolationError, '' ): await self.con.execute(r
test_edgeql_vector_constraint_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def _check_index(self, obj, func, index_type, index_op, vec_type): # Test that we actually hit the indexes by looking at the query plans. obj_id = (await self.con.query_single(f""" insert {obj} {{ vec := [1, 1, 2] }} """)).id await self.con.execute(f""" insert {obj} {{ vec := [-1, -1, 2] }} """) embedding = [0.5, -0.1, 0.666] await self._assert_index_use( f''' with vec as module ext::pgvector, base := (select {obj} filter .id = <uuid>$0), select {obj} filter {obj}.id != base.id order by vec::{func}(.vec, base.vec) empty last limit 5; ''', obj_id, index_type=index_type, index_op=index_op, ) await self._assert_index_use( f''' with vec as module ext::pgvector select {obj} order by vec::{func}(.vec, <{vec_type}>to_json(<str>$0)) empty last limit 5; ''', str(embedding), index_type=index_type, index_op=index_op, ) await self._assert_index_use( f''' with vec as module ext::pgvector select {obj} order by vec::{func}(.vec, <{vec_type}><json>$0) empty last limit 5; ''', json.dumps(embedding), index_type=index_type, index_op=index_op, ) await self._assert_index_use( f''' with vec as module ext::pgvector select {obj} order by vec::{func}(.vec, <{vec_type}><array<float32>>$0) empty last limit 5; ''', embedding, index_type=index_type, index_op=index_op, )
)).id await self.con.execute(f
_check_index
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_vector_config(self): # We can't test the effects of config parameters easily, but we can # at least verify that they are updated as expected. # The pgvector configs don't seem to show up in # current_setting unless we've done something involving vector # on the connection... await self.con.query(''' select <ext::pgvector::vector>[3, 4]; ''') # probes await self.assert_query_result( 'select <int64>_current_setting("ivfflat.probes")', [1], ) await self.con.execute(''' configure session set ext::pgvector::Config::probes := 23 ''') await self.assert_query_result( 'select <int64>_current_setting("ivfflat.probes")', [23], ) await self.con.execute(''' configure session reset ext::pgvector::Config::probes ''') await self.assert_query_result( 'select <int64>_current_setting("ivfflat.probes")', [1], ) # ef_search await self.assert_query_result( 'select <int64>_current_setting("hnsw.ef_search")', [40], ) await self.con.execute(''' configure session set ext::pgvector::Config::ef_search := 23 ''') await self.assert_query_result( 'select <int64>_current_setting("hnsw.ef_search")', [23], ) await self.con.execute(''' configure session reset ext::pgvector::Config::ef_search ''') await self.assert_query_result( 'select <int64>_current_setting("hnsw.ef_search")', [40], )
) # probes await self.assert_query_result( 'select <int64>_current_setting("ivfflat.probes")', [1], ) await self.con.execute(
test_edgeql_vector_config
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_01(self): # Basic casts to and from json. Also a cast into an # array<float32>. await self.assert_query_result( ''' select <json><ext::pgvector::halfvec>[1, 2, 3.5]; ''', [[1, 2, 3.5]], json_only=True, ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec> to_json('[1.5, 2, 3]'); ''', [[1.5, 2, 3]], )
select <json><ext::pgvector::halfvec>[1, 2, 3.5]; ''', [[1, 2, 3.5]], json_only=True, ) await self.assert_query_result(
test_edgeql_halfvec_cast_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_02(self): # Basic casts from json. await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec>to_json(( select _ := Basic.p_str order by _ )) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec>( select _ := Basic.p_json order by _ ) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, )
select <array<float32>><ext::pgvector::halfvec>to_json(( select _ := Basic.p_str order by _ )) ''', [[0, 1, 2.3], [1, 1, 10.11], [4.5, 6.7, 8.9]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result(
test_edgeql_halfvec_cast_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_03(self): # Casts from numeric array expressions. await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<int16>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<int32>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<int64>>[1.0, 2.0, 3.0]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<float32>>[1.5, 2, 3]; ''', [[1.5, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<float64>>[1, 2, 3]; ''', [[1, 2, 3]], )
select <array<float32>> <ext::pgvector::halfvec><array<int16>>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result(
test_edgeql_halfvec_cast_03
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_04(self): # Casts from numeric array expressions. res = [0, 3, 4, 7] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_int16 order by Raw.p_int16 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_int32 order by Raw.p_int32 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_int64 order by Raw.p_int64 ); ''', [res], )
select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_int16 order by Raw.p_int16 ); ''', [res], ) await self.assert_query_result(
test_edgeql_halfvec_cast_04
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_05(self): # Casts from numeric array expressions. res = [0, 3, 4.25, 6.75] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_float32 order by Raw.p_float32 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.val order by Raw.val ); ''', [res], )
select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_float32 order by Raw.p_float32 ); ''', [res], ) await self.assert_query_result(
test_edgeql_halfvec_cast_05
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_06(self): # Casts from literal numeric arrays. await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec> [<int16>1, <int16>2, <int16>3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec> [<int32>1, <int32>2, <int32>3]; ''', [[1, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec>[1.5, 2, 3]; ''', [[1.5, 2, 3]], ) await self.assert_query_result( ''' select <array<float32>><ext::pgvector::halfvec> [<float32>1.5, <float32>2, <float32>3]; ''', [[1.5, 2, 3]], )
select <array<float32>><ext::pgvector::halfvec>[1, 2, 3]; ''', [[1, 2, 3]], ) await self.assert_query_result(
test_edgeql_halfvec_cast_06
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_08(self): # Casts from arrays of derived types. await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<myf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec><array<deepf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg(<myf64>{1, 2.3, 4.5}); ''', [[1, 2.3, 4.5]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg(<deepf64>{1, 2.3, 4.5}); ''', [[1, 2.3, 4.5]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, )
select <array<float32>> <ext::pgvector::halfvec><array<myf64>>[1, 2.3, 4.5]; ''', [[1, 2.3, 4.5]], # halfvecs will lose a fair bit of precision in convertions rel_tol=0.01, ) await self.assert_query_result(
test_edgeql_halfvec_cast_08
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_09(self): # Casts from arrays of derived types. res = [0, 3, 4.25, 6.75] await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_myf64 order by Raw.p_myf64 ); ''', [res], ) await self.assert_query_result( ''' select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_deepf64 order by Raw.p_deepf64 ); ''', [res], )
select <array<float32>> <ext::pgvector::halfvec>array_agg( Raw.p_myf64 order by Raw.p_myf64 ); ''', [res], ) await self.assert_query_result(
test_edgeql_halfvec_cast_09
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_cast_10(self): # Arrays of vectors. await self.assert_query_result( ''' with module ext::pgvector select [ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, ) # Arrays of vectors. await self.assert_query_result( ''' with module ext::pgvector select <json>[ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, )
with module ext::pgvector select [ <vector>[0, 1], <vector>[2, 3], <vector>[4, 5, 6], ] ''', [[[0, 1], [2, 3], [4, 5, 6]]], json_only=True, ) # Arrays of vectors. await self.assert_query_result(
test_edgeql_halfvec_cast_10
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_op_01(self): # Comparison operators. await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2, 3] = <ext::pgvector::halfvec>[0, 1, 1]; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2, 3] != <ext::pgvector::halfvec>[0, 1, 1]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2, 3] ?= <ext::pgvector::halfvec>{}; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2, 3] ?!= <ext::pgvector::halfvec>{}; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>{} ?= <ext::pgvector::halfvec>{}; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2] < <ext::pgvector::halfvec>[2, 3]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2] <= <ext::pgvector::halfvec>[2, 3]; ''', [True], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2] > <ext::pgvector::halfvec>[2, 3]; ''', [False], ) await self.assert_query_result( ''' select <ext::pgvector::halfvec>[1, 2] >= <ext::pgvector::halfvec>[2, 3]; ''', [False], )
select <ext::pgvector::halfvec>[1, 2, 3] = <ext::pgvector::halfvec>[0, 1, 1]; ''', [False], ) await self.assert_query_result(
test_edgeql_halfvec_op_01
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_op_02(self): await self.assert_query_result( ''' with module ext::pgvector select <halfvec>to_json('[3, 0]') in { <halfvec>to_json('[1, 2]'), <halfvec>to_json('[3, 4]'), }; ''', [False], ) await self.assert_query_result( ''' with module ext::pgvector select <halfvec>to_json('[3, 0]') not in { <halfvec>to_json('[1, 2]'), <halfvec>to_json('[3, 4]'), }; ''', [True], )
with module ext::pgvector select <halfvec>to_json('[3, 0]') in { <halfvec>to_json('[1, 2]'), <halfvec>to_json('[3, 4]'), }; ''', [False], ) await self.assert_query_result(
test_edgeql_halfvec_op_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0
async def test_edgeql_halfvec_func_02(self): async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <halfvec>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, 3, 0) """) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <halfvec>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, -2, 1) """) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r""" with module ext::pgvector, x := <halfvec>[1, 3, 0, 6, 7] select <array<float32>>subvector(x, 20, 2) """)
) async with self.assertRaisesRegexTx( edgedb.errors.InvalidValueError, 'must have at least 1 dimension', ): await self.con.execute(r
test_edgeql_halfvec_func_02
python
geldata/gel
tests/test_edgeql_vector.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_vector.py
Apache-2.0