-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/controllers
- Loading branch information
Showing
49 changed files
with
484 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from evidently.features import is_valid_sql_feature | ||
from evidently.features.generated_features import FeatureDescriptor | ||
from evidently.features.generated_features import GeneratedFeature | ||
|
||
|
||
class IsValidSQL(FeatureDescriptor): | ||
class Config: | ||
type_alias = "evidently:descriptor:IsValidSQL" | ||
|
||
def feature(self, column_name: str) -> GeneratedFeature: | ||
return is_valid_sql_feature.IsValidSQL(column_name, self.display_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Any | ||
from typing import ClassVar | ||
from typing import Optional | ||
|
||
from evidently import ColumnType | ||
from evidently.features.generated_features import ApplyColumnGeneratedFeature | ||
|
||
|
||
class IsValidSQL(ApplyColumnGeneratedFeature): | ||
class Config: | ||
type_alias = "evidently:feature:IsValidSQL" | ||
|
||
__feature_type__: ClassVar = ColumnType.Categorical | ||
display_name_template: ClassVar = "SQL Validity Check for {column_name}" | ||
column_name: str | ||
|
||
def __init__(self, column_name: str, display_name: Optional[str] = None): | ||
self.column_name = column_name | ||
self.display_name = display_name | ||
super().__init__() | ||
|
||
def apply(self, value: Any): | ||
if value is None or not isinstance(value, str): | ||
return False | ||
|
||
return self.is_valid_sql(value) | ||
|
||
def is_valid_sql(self, query: str) -> bool: | ||
import sqlvalidator | ||
|
||
queries = query.strip().split(";") # Split by semicolon | ||
|
||
for q in queries: | ||
q = q.strip() # Remove extra whitespace | ||
if not q: # Skip empty queries | ||
continue | ||
|
||
try: | ||
sqlvalidator.format_sql(q) # Validate SQL syntax | ||
except Exception: | ||
return False # Invalid SQL | ||
|
||
return True # All queries are valid |
Oops, something went wrong.