sqlalchemy-risingwave 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/PKG-INFO +1 -1
  2. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave/__init__.py +1 -1
  3. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave/base.py +43 -2
  4. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/PKG-INFO +1 -1
  5. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/LICENSE +0 -0
  6. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/README.md +0 -0
  7. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/setup.cfg +0 -0
  8. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/setup.py +0 -0
  9. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave/psycopg2.py +0 -0
  10. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave/requirements.py +0 -0
  11. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/SOURCES.txt +0 -0
  12. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/dependency_links.txt +0 -0
  13. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/entry_points.txt +0 -0
  14. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/not-zip-safe +0 -0
  15. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/requires.txt +0 -0
  16. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/sqlalchemy_risingwave.egg-info/top_level.txt +0 -0
  17. {sqlalchemy-risingwave-1.0.0 → sqlalchemy-risingwave-1.0.1}/test/test_schema.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy-risingwave
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: RisingWave dialect for SQLAlchemy
5
5
  Home-page: https://github.com/risingwavelabs/risingwave
6
6
  Author: RisingWave Labs
@@ -1,6 +1,6 @@
1
1
  from sqlalchemy.dialects import registry as _registry
2
2
 
3
- __version__ = "1.0.0"
3
+ __version__ = "1.0.1"
4
4
 
5
5
  _registry.register(
6
6
  "risingwave.psycopg2",
@@ -5,6 +5,7 @@ from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
5
5
  from sqlalchemy import text
6
6
  from sqlalchemy.util import warn
7
7
 
8
+ from sqlalchemy import util
8
9
  import sqlalchemy.types as sqltypes
9
10
 
10
11
  _type_map = {
@@ -74,8 +75,16 @@ class RisingWaveDialect(PGDialect_psycopg2):
74
75
  sql += f" WHERE schemaname = '{schema or self.default_schema_name}'"
75
76
  else:
76
77
  sql += " WHERE schemaname <> 'rw_catalog' and schemaname <> 'pg_catalog' and schemaname <> 'information_schema'"
77
- rows = conn.execute(text(sql))
78
- return [row.viewname for row in rows]
78
+ views = conn.execute(text(sql))
79
+
80
+ # As sqlalchmey has no support for Sources, we categorize as view temporarily.
81
+ source_sql = f"SELECT rw_catalog.rw_sources.name as source_name FROM rw_catalog.rw_sources JOIN rw_catalog.rw_schemas ON rw_catalog.rw_sources.schema_id = rw_catalog.rw_schemas.id"
82
+ if schema is not None:
83
+ source_sql += f" WHERE rw_catalog.rw_schemas.name = '{schema or self.default_schema_name}'"
84
+ else:
85
+ source_sql += " WHERE rw_catalog.rw_schemas.name <> 'rw_catalog' and rw_catalog.rw_schemas.name <> 'pg_catalog' and rw_catalog.rw_schemas.name <> 'information_schema'"
86
+ sources = conn.execute(text(source_sql))
87
+ return [view.viewname for view in views] + [source.source_name for source in sources]
79
88
 
80
89
  def has_table(self, conn, table, schema=None, **kw):
81
90
  return any(t == table for t in self.get_table_names(conn, schema=schema))
@@ -134,6 +143,38 @@ class RisingWaveDialect(PGDialect_psycopg2):
134
143
  res.append(column_info)
135
144
  return res
136
145
 
146
+ def get_table_oid(self, connection, table_name, schema=None, **kw):
147
+ table_oid = None
148
+ if schema is not None:
149
+ schema_where_clause = "n.nspname = :schema"
150
+ else:
151
+ schema_where_clause = "pg_catalog.pg_table_is_visible(r.id)"
152
+ query = (
153
+ """
154
+ SELECT r.id as oid
155
+ FROM rw_catalog.rw_relations r
156
+ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = r.schema_id
157
+ WHERE (%s)
158
+ AND r.name = :table_name AND r.relation_type in
159
+ ('table', 'system table', 'view', 'materialized view', 'source', 'sink')
160
+ """
161
+ % schema_where_clause
162
+ )
163
+ # Since we're binding to unicode, table_name and schema_name must be
164
+ # unicode.
165
+ table_name = util.text_type(table_name)
166
+ if schema is not None:
167
+ schema = util.text_type(schema)
168
+ s = text(query).bindparams(table_name=sqltypes.Unicode)
169
+ s = s.columns(oid=sqltypes.Integer)
170
+ if schema:
171
+ s = s.bindparams(sql.bindparam("schema", type_=sqltypes.Unicode))
172
+ c = connection.execute(s, dict(table_name=table_name, schema=schema))
173
+ table_oid = c.scalar()
174
+ if table_oid is None:
175
+ raise exc.NoSuchTableError(table_name)
176
+ return table_oid
177
+
137
178
  def get_indexes(self, conn, table_name, schema=None, **kw):
138
179
  table_oid = self.get_table_oid(
139
180
  conn, table_name, schema, info_cache=kw.get("info_cache")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy-risingwave
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: RisingWave dialect for SQLAlchemy
5
5
  Home-page: https://github.com/risingwavelabs/risingwave
6
6
  Author: RisingWave Labs