Skip to content

Commit

Permalink
feat: configure DEFAULT_SCHEMA (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Jan 6, 2024
1 parent c84110d commit b83aaf6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
39 changes: 39 additions & 0 deletions docs/gear_up/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*************
Configuration
*************

The SQLLineage configuration allows user to customize the behaviour of sqllineage.

We adopt environment variable approach for global key-value mapping. The keys listed in this section should start with
`"SQLLINEAGE_"` to be a valid config. For example, to use DEFAULT_SCHEMA, use ``SQLLINEAGE_DEFAULT_SCHEMA=default``.

DEFAULT_SCHEMA
==============
Default schema, or interchangeably called database. Tables without schema qualifier parsed from SQL is set with a schema
named `<default>`, which represents an unknown schema name. If DEFAULT_SCHEMA is set, we will use this value as
default schema name.

Default: ``""``

DIRECTORY
=========
Frontend app SQL directory. By default the frontend app is showing the data directory packaged with sqllineage,
which includes tpcds queries for demo purposes. User can customize with this key.

Default: ``sqllineage/data``

TSQL_NO_SEMICOLON
=================
Enable tsql no semicolon splitter mode.

.. warning::
Transact-SQL offers this feature that even when SQL statements are not delimited by semicolon, it can still be
parsed and executed. But quoting `tsql_syntax_convention`_, "although the semicolon isn't required for most
statements in this version (v16) of SQL Server, it will be required in a future version". So this config key is
kept mostly for backward-compatible purposes. We may drop the support any time without warning. Bear this in mind
when using this feature with sqllineage.

Default: ``False``


.. _tsql_syntax_convention: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/transact-sql-syntax-conventions-transact-sql?view=sql-server-ver16
14 changes: 14 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ First steps
Using SQLLineage in your Python script


Gear Up
=======

.. toctree::
:maxdepth: 2
:hidden:
:caption: Gear up

gear_up/configuration

:doc:`gear_up/configuration`
Learn how to configure sqllineage


Behind the scene
================

Expand Down
2 changes: 2 additions & 0 deletions sqllineage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class _SQLLineageConfigLoader:
config = {
# for frontend directory drawer
"DIRECTORY": (str, os.path.join(os.path.dirname(__file__), "data")),
# set default schema/database
"DEFAULT_SCHEMA": (str, ""),
# to enable tsql no semicolon splitter mode
"TSQL_NO_SEMICOLON": (bool, False),
}
Expand Down
6 changes: 4 additions & 2 deletions sqllineage/core/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
from typing import Any, Dict, List, Optional, Set, Union

from sqllineage.config import SQLLineageConfig
from sqllineage.exceptions import SQLLineageException
from sqllineage.utils.helpers import escape_identifier_name

Expand All @@ -11,8 +12,9 @@ class Schema:
"""

unknown = "<default>"
default = SQLLineageConfig.DEFAULT_SCHEMA or unknown

def __init__(self, name: str = unknown):
def __init__(self, name: str = default):
"""
:param name: schema name
"""
Expand All @@ -31,7 +33,7 @@ def __hash__(self):
return hash(str(self))

def __bool__(self):
return str(self) != self.unknown
return str(self) != self.default


class Table:
Expand Down

0 comments on commit b83aaf6

Please sign in to comment.