[Enhancement] Support read from catalog through source in dbt (#31641)
Signed-off-by: Astralidea <astralidea@163.com>
This commit is contained in:
parent
e4485112d0
commit
580f276f7a
|
|
@ -100,6 +100,31 @@ models:
|
|||
```
|
||||
For materialized view only support partition_by、buckets、distributed_by、properties、refresh_method configuration.
|
||||
|
||||
## Read From Catalog
|
||||
First you need to add this catalog to starrocks. The following is an example of hive.
|
||||
```mysql
|
||||
CREATE EXTERNAL CATALOG `hive_catalog`
|
||||
PROPERTIES (
|
||||
"hive.metastore.uris" = "thrift://127.0.0.1:8087",
|
||||
"type"="hive"
|
||||
);
|
||||
```
|
||||
How to add other types of catalogs can be found in the documentation.
|
||||
https://docs.starrocks.io/en-us/latest/data_source/catalog/catalog_overview
|
||||
Then write the sources.yaml file.
|
||||
```yaml
|
||||
sources:
|
||||
- name: external_example
|
||||
schema: hive_catalog.hive_db
|
||||
tables:
|
||||
- name: hive_table_name
|
||||
```
|
||||
Finally, you might use below marco quote
|
||||
```
|
||||
{{ source('external_example', 'hive_table_name') }}
|
||||
```
|
||||
|
||||
|
||||
## Test Adapter
|
||||
consult [the project](https://github.com/dbt-labs/dbt-adapter-tests)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
version = "1.3.2"
|
||||
version = "1.4.0"
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ logger = AdapterLogger("starrocks")
|
|||
class StarRocksCredentials(Credentials):
|
||||
host: Optional[str] = None
|
||||
port: Optional[int] = None
|
||||
catalog: Optional[str] = 'default_catalog'
|
||||
database: Optional[str] = None
|
||||
schema: Optional[str] = None
|
||||
username: Optional[str] = None
|
||||
|
|
@ -72,8 +73,8 @@ class StarRocksCredentials(Credentials):
|
|||
return (
|
||||
"host",
|
||||
"port",
|
||||
"database",
|
||||
"schema",
|
||||
"catalog",
|
||||
"username",
|
||||
)
|
||||
|
||||
|
|
@ -102,8 +103,8 @@ class StarRocksConnectionManager(SQLConnectionManager):
|
|||
return connection
|
||||
|
||||
credentials = cls.get_credentials(connection.credentials)
|
||||
kwargs = {"host": credentials.host, "username": credentials.username, "password": credentials.password,
|
||||
"database": credentials.schema}
|
||||
kwargs = {"host": credentials.host, "username": credentials.username,
|
||||
"password": credentials.password, "database": credentials.catalog + "." + credentials.schema}
|
||||
|
||||
if credentials.port:
|
||||
kwargs["port"] = credentials.port
|
||||
|
|
|
|||
|
|
@ -46,6 +46,22 @@ class StarRocksRelation(BaseRelation):
|
|||
quote_policy: StarRocksQuotePolicy = field(default_factory=lambda: StarRocksQuotePolicy())
|
||||
quote_character: str = "`"
|
||||
|
||||
def quoted(self, identifier):
|
||||
if '.' in identifier:
|
||||
catalog_db = identifier.split('.')
|
||||
catalog = catalog_db[0]
|
||||
db = catalog_db[1]
|
||||
return "{quote_char}{catalog}{quote_char}.{quote_char}{db}{quote_char}".format(
|
||||
quote_char=self.quote_character,
|
||||
catalog=catalog,
|
||||
db=db
|
||||
)
|
||||
else:
|
||||
return "{quote_char}{identifier}{quote_char}".format(
|
||||
quote_char=self.quote_character,
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
@property
|
||||
def is_materialized_view(self) -> bool:
|
||||
return self.type == StarRocksRelationType.MaterializedView
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ with open(os.path.join(this_directory, "README.md")) as f:
|
|||
|
||||
package_name = "dbt-starrocks"
|
||||
# make sure this always matches dbt/adapters/starrocks/__version__.py
|
||||
package_version = "1.3.2"
|
||||
package_version = "1.4.0"
|
||||
description = """The Starrocks adapter plugin for dbt"""
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue