Skip to content

Commit

Permalink
Add logging Warnings into Queries and Query Builders (#616)
Browse files Browse the repository at this point in the history
* add warnings to use query builder

Signed-off-by: Chloe Ching <[email protected]>

* add warnings for user to use query builders

Signed-off-by: Chloe Ching <[email protected]>

* warning logs for weather querybuilder

Signed-off-by: Chloe Ching <[email protected]>

* update warning message

Signed-off-by: Chloe Ching <[email protected]>

* update time series query builder

Signed-off-by: Chloe Ching <[email protected]>

---------

Signed-off-by: Chloe Ching <[email protected]>
  • Loading branch information
cching95 authored Dec 18, 2023
1 parent 411fdab commit 19421b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from jinja2 import Template
import datetime
import logging
from datetime import datetime, time
from .._utilities_query_builder import (
_is_date_format,
Expand All @@ -22,7 +23,6 @@
_convert_to_seconds,
)


TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
seconds_per_unit = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}

Expand Down Expand Up @@ -608,6 +608,11 @@ def _summary_query(parameters_dict: dict) -> str:


def _query_builder(parameters_dict: dict, query_type: str) -> str:
if "supress_warning" not in parameters_dict:
logging.warning(
"Please use the TimeSeriesQueryBuilder() to build time series queries."
)

if "tag_names" not in parameters_dict:
parameters_dict["tag_names"] = []
tagnames_deduplicated = list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pandas import DataFrame


class QueryBuilder:
class TimeSeriesQueryBuilder:
"""
A builder for developing RTDIP queries using any delta table.
"""
Expand Down Expand Up @@ -113,6 +113,7 @@ def raw(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}
return raw.get(self.connection, raw_parameters)

Expand Down Expand Up @@ -164,6 +165,7 @@ def resample(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return resample.get(self.connection, resample_parameters)
Expand Down Expand Up @@ -218,6 +220,7 @@ def interpolate(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return interpolate.get(self.connection, interpolation_parameters)
Expand Down Expand Up @@ -260,6 +263,7 @@ def interpolation_at_time(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return interpolation_at_time.get(
Expand Down Expand Up @@ -321,6 +325,7 @@ def time_weighted_average(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return time_weighted_average.get(
Expand Down Expand Up @@ -350,6 +355,7 @@ def metadata(
"tagname_column": self.tagname_column,
"limit": limit,
"offset": offset,
"supress_warning": True,
}

return metadata.get(self.connection, metadata_parameters)
Expand Down Expand Up @@ -377,6 +383,7 @@ def latest(
"tagname_column": self.tagname_column,
"limit": limit,
"offset": offset,
"supress_warning": True,
}

return latest.get(self.connection, latest_parameters)
Expand Down Expand Up @@ -431,6 +438,7 @@ def circular_average(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return circular_average.get(self.connection, circular_average_parameters)
Expand Down Expand Up @@ -485,6 +493,7 @@ def circular_standard_deviation(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}

return circular_standard_deviation.get(
Expand Down Expand Up @@ -526,5 +535,6 @@ def summary(
"timestamp_column": self.timestamp_column,
"status_column": self.status_column,
"value_column": self.value_column,
"supress_warning": True,
}
return summary.get(self.connection, summary_parameters)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from jinja2 import Template
import logging
import datetime
from datetime import datetime, time
from .._utilities_query_builder import (
Expand Down Expand Up @@ -187,6 +188,9 @@ def _latest_query_point(parameters_dict: dict) -> str:


def _query_builder(parameters_dict: dict, query_type: str) -> str:
if "supress_warning" not in parameters_dict:
logging.warning("Please use the WeatherQueryBuilder() to build weather queries")

if query_type == "latest_point":
return _latest_query_point(parameters_dict)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def raw_point(
"time_zone": time_zone,
"include_bad_data": include_bad_data,
"limit": limit,
"supress_warning": True,
}

return raw.get_point(self.connection, raw_parameters)
Expand Down Expand Up @@ -152,6 +153,7 @@ def latest_point(
"lon": lon,
"source": source,
"limit": limit,
"supress_warning": True,
}

return latest.get_point(self.connection, raw_parameters)
Expand Down Expand Up @@ -210,6 +212,7 @@ def raw_grid( # NOSONAR
"time_zone": time_zone,
"include_bad_data": include_bad_data,
"limit": limit,
"supress_warning": True,
}

return raw.get_grid(self.connection, raw_parameters)
Expand Down Expand Up @@ -256,6 +259,7 @@ def latest_grid(
"max_lon": max_lon,
"source": source,
"limit": limit,
"supress_warning": True,
}

return latest.get_grid(self.connection, raw_parameters)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from src.sdk.python.rtdip_sdk.queries.time_series.time_series_query_builder import (
QueryBuilder,
TimeSeriesQueryBuilder,
)
from src.sdk.python.rtdip_sdk.connectors import DatabricksSQLConnection
from src.sdk.python.rtdip_sdk.authentication.azure import DefaultAuth
Expand All @@ -29,7 +29,7 @@ def test_query_builder_raw(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.raw(
Expand All @@ -46,7 +46,7 @@ def test_query_builder_resample(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE)
.resample(
Expand All @@ -68,7 +68,7 @@ def test_query_builder_interpolate(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source("mock_catalog.mock_scema.mock_table", status_column=None)
.interpolate(
Expand All @@ -91,7 +91,7 @@ def test_query_builder_interpolation_at_time(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.interpolation_at_time(
Expand All @@ -109,7 +109,7 @@ def test_query_builder_twa(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.time_weighted_average(
Expand All @@ -132,7 +132,7 @@ def test_query_builder_metadata(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE)
.metadata(tagname_filter=["mock_tag"])
Expand All @@ -147,7 +147,7 @@ def test_query_builder_latest(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE)
.latest(tagname_filter=["mock_tag"])
Expand All @@ -162,7 +162,7 @@ def test_query_builder_circular_average(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.circular_average(
Expand All @@ -185,7 +185,7 @@ def test_query_builder_circular_standard_deviation(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.circular_standard_deviation(
Expand All @@ -208,7 +208,7 @@ def test_query_builder_summary(mocker: MockerFixture):
)

data = (
QueryBuilder()
TimeSeriesQueryBuilder()
.connect(MOCK_CONNECTION)
.source(MOCK_TABLE, status_column=None)
.summary(
Expand Down

0 comments on commit 19421b6

Please sign in to comment.