Repository: macbre/sql-metadata

Issue:
query_type method logs the SQL Query if unsupported.
The `query_type` method checks if it is a supported type, if not, it raises an error and logs the actual raw query. 
This might be undesirable, for it may contain PIIs on the query itself. 

``` python
if tokens[index].normalized == "CREATE":
    switch = self._get_switch_by_create_query(tokens, index)
elif tokens[index].normalized in ("ALTER", "DROP", "TRUNCATE"):
    switch = tokens[index].normalized + tokens[index + 1].normalized
else:
    switch = tokens[index].normalized
self._query_type = SUPPORTED_QUERY_TYPES.get(switch, "UNSUPPORTED")
if self._query_type == "UNSUPPORTED":
    self._logger.error("Not supported query type: %s", self._raw_query)
    raise ValueError("Not supported query type!")
return self._query_type
```

My suggestion would be to log only the switch that's not included in the supported types, or give an option for suppressing the logs as a method argument. 

Thank you.

Hints from issue comments:

Solution patch:
diff --git a/sql_metadata/parser.py b/sql_metadata/parser.py
index 5c61dca8..8e61fab9 100644
--- a/sql_metadata/parser.py
+++ b/sql_metadata/parser.py
@@ -122,7 +122,11 @@ def query_type(self) -> str:
             switch = tokens[index].normalized
         self._query_type = SUPPORTED_QUERY_TYPES.get(switch, "UNSUPPORTED")
         if self._query_type == "UNSUPPORTED":
-            self._logger.error("Not supported query type: %s", self._raw_query)
+            # do not log the full query
+            # https://github.com/macbre/sql-metadata/issues/543
+            shorten_query = " ".join(self._raw_query.split(" ")[:3])
+
+            self._logger.error("Not supported query type: %s", shorten_query)
             raise ValueError("Not supported query type!")
         return self._query_type
 


Test patch:
diff --git a/test/test_query_type.py b/test/test_query_type.py
index 8e1a92e3..b9e3486f 100644
--- a/test/test_query_type.py
+++ b/test/test_query_type.py
@@ -48,10 +48,10 @@ def test_drop_table_query():
             assert "DROP TABLE" == Parser(query.format(comment)).query_type
 
 
-def test_unsupported_query():
+def test_unsupported_query(caplog):
     queries = [
-        "FOO BAR",
-        "DO SOMETHING",
+        "FOO BAR LONG QUERY WITH MANY TOKENS",
+        "DO SOMETHING LONG QUERY",
     ]
 
     for query in queries:
@@ -60,6 +60,15 @@ def test_unsupported_query():
 
         assert "Not supported query type!" in str(ex.value)
 
+        # assert the SQL query is not logged
+        # https://docs.pytest.org/en/stable/how-to/logging.html#caplog-fixture
+        assert (
+            f"Not supported query type: {query}" not in caplog.text
+        ), "The SQL query should not be logged"
+        assert (
+            f"Not supported query type: {query[:8]}" in caplog.text
+        ), "The SQL query should be trimmed when logged"
+
 
 def test_empty_query():
     queries = ["", "/* empty query */"]