diff --git a/api/cueSearch/tests/test_elasticSearch_indexing.py b/api/cueSearch/tests/test_elasticSearch_indexing.py index 56923678..d79e02e1 100644 --- a/api/cueSearch/tests/test_elasticSearch_indexing.py +++ b/api/cueSearch/tests/test_elasticSearch_indexing.py @@ -455,115 +455,116 @@ def testFindNonGlobalDimensionSuggestionResult(client, mocker): ################################ Delete all indexes ############## -# @pytest.mark.django_db(transaction=True) -# def testFindNonGlobalDimensionResultData(client, mocker): -# """Method to test non global dimension index""" -# ESIndexingUtils.deleteAllIndex() - -# connection = mixer.blend("dataset.connection") -# testDataset = mixer.blend( -# "dataset.dataset", -# name="orders", -# id=1, -# dimensions='["Brand", "Color", "State"]', -# metrics='["Orders", "OrderAmount", "OrderQuantity"]', -# granularity="day", -# timestampColumn="TestDate", -# sql="Select * from testTable", -# ) -# mockResponse = mocker.patch( -# "cueSearch.elasticSearch.elastic_search_indexing.ESIndexingUtils.runAllIndexDimension", -# new=mock.MagicMock(autospec=True, return_value=True), -# ) -# mockResponse.start() -# path = reverse("createDataset") -# data = { -# "name": "demo_dataset", -# "sql": "SELECT * from TEST_TABLE", -# "connectionId": connection.id, -# "metrics": ["Amount", "Quantity"], -# "dimensions": ["Category", "Region"], -# "timestamp": "CreatedAt", -# "granularity": "day", -# "isNonRollup": False, -# } -# response = client.post(path, data=data, content_type="application/json") - -# # create dimension for testing -# dataset = Dataset.objects.get(id=1) -# mockResponse.start() -# path = reverse("globalDimensionCreate") -# gd_data = { -# "name": "test", -# "dimensionalValues": [ -# { -# "datasetId": dataset.id, -# "dataset": "Returns", -# "dimension": "WarehouseCode", -# } -# ], -# } -# response = client.post(path, gd_data, content_type="application/json") -# assert response.data["success"] == True -# assert response.status_code == 200 - -# globalDimsId = GlobalDimensionServices.getGlobalDimensions() -# globalDimensionId = globalDimsId.data[0]["values"][0]["id"] - -# # Publishing global dimension by id -# path = reverse("pubGlobalDimension") -# payload = {"id": globalDimensionId, "published": True} -# response = client.post(path, payload) -# mockResponse.stop() -# listToIndex = [ -# {"dataset": "Test data", "datasetId": 1, "dimension": "Brand"}, -# {"dataset": "Test data", "datasetId": 1, "dimension": "WarehouseCode"}, -# ] -# res = {"success": True, "data": listToIndex} - -# mockResponse = mocker.patch( -# "cueSearch.services.globalDimension.GlobalDimensionServices.nonGlobalDimensionForIndexing", -# new=mock.MagicMock(autospec=True, return_value=res), -# ) -# mockResponse.start() -# ESIndexingUtils.indexNonGlobalDimensionsData() -# mockResponse.stop() - -# expectedResults = [ -# { -# "value": "TestData", -# "dimension": "Brand", -# "globalDimensionName": "Test data_Brand", -# "user_entity_identifier": "Test data_Brand", -# "id": "Brand_TestData_1", -# "dataset": "Test data", -# "datasetId": testDataset.id, -# "type": "DATASETDIMENSION", -# }, -# { -# "value": "TestData", -# "dimension": "WarehouseCode", -# "globalDimensionName": "Test data_WarehouseCode", -# "user_entity_identifier": "Test data_WarehouseCode", -# "id": "WarehouseCode_TestData_1", -# "dataset": "Test data", -# "datasetId": testDataset.id, -# "type": "DATASETDIMENSION", -# }, -# ] -# query = "TestData" -# result = ESQueryingUtils.findNonGlobalDimensionResults(query=query) -# count = 0 -# while not result: -# count += 1 -# result = ESQueryingUtils.findNonGlobalDimensionResults(query=query) - -# if count == 10: -# result = [] -# return result - -# assert result == expectedResults -# ################################ Delete all indexes ############## +@pytest.mark.django_db(transaction=True) +def testFindNonGlobalDimensionResultData(client, mocker): + """Method to test non global dimension index""" + ESIndexingUtils.deleteAllIndex() + + connection = mixer.blend("dataset.connection") + testDataset = mixer.blend( + "dataset.dataset", + name="orders", + id=1, + dimensions='["Brand", "Color", "State"]', + metrics='["Orders", "OrderAmount", "OrderQuantity"]', + granularity="day", + timestampColumn="TestDate", + sql="Select * from testTable", + ) + mockResponse = mocker.patch( + "cueSearch.elasticSearch.elastic_search_indexing.ESIndexingUtils.runAllIndexDimension", + new=mock.MagicMock(autospec=True, return_value=True), + ) + mockResponse.start() + path = reverse("createDataset") + data = { + "name": "demo_dataset", + "sql": "SELECT * from TEST_TABLE", + "connectionId": connection.id, + "metrics": ["Amount", "Quantity"], + "dimensions": ["Category", "Region"], + "timestamp": "CreatedAt", + "granularity": "day", + "isNonRollup": False, + } + response = client.post(path, data=data, content_type="application/json") + + # create dimension for testing + dataset = Dataset.objects.get(id=1) + mockResponse.start() + path = reverse("globalDimensionCreate") + gd_data = { + "name": "test", + "dimensionalValues": [ + { + "datasetId": dataset.id, + "dataset": "Returns", + "dimension": "WarehouseCode", + } + ], + } + response = client.post(path, gd_data, content_type="application/json") + assert response.data["success"] == True + assert response.status_code == 200 + + globalDimsId = GlobalDimensionServices.getGlobalDimensions() + globalDimensionId = globalDimsId.data[0]["values"][0]["id"] + + # Publishing global dimension by id + path = reverse("pubGlobalDimension") + payload = {"id": globalDimensionId, "published": True} + response = client.post(path, payload) + mockResponse.stop() + listToIndex = [ + {"dataset": "Test data", "datasetId": 1, "dimension": "Brand"}, + {"dataset": "Test data", "datasetId": 1, "dimension": "WarehouseCode"}, + ] + res = {"success": True, "data": listToIndex} + + mockResponse = mocker.patch( + "cueSearch.services.globalDimension.GlobalDimensionServices.nonGlobalDimensionForIndexing", + new=mock.MagicMock(autospec=True, return_value=res), + ) + mockResponse.start() + ESIndexingUtils.indexNonGlobalDimensionsData() + mockResponse.stop() + + expectedResults = [ + { + "value": "TestData", + "dimension": "Brand", + "globalDimensionName": "Test data_Brand", + "user_entity_identifier": "Test data_Brand", + "id": "Brand_TestData_1", + "dataset": "Test data", + "datasetId": testDataset.id, + "type": "DATASETDIMENSION", + }, + { + "value": "TestData", + "dimension": "WarehouseCode", + "globalDimensionName": "Test data_WarehouseCode", + "user_entity_identifier": "Test data_WarehouseCode", + "id": "WarehouseCode_TestData_1", + "dataset": "Test data", + "datasetId": testDataset.id, + "type": "DATASETDIMENSION", + }, + ] + query = "TestData" + result = ESQueryingUtils.findNonGlobalDimensionResults(query=query) + count = 0 + while not result: + count += 1 + result = ESQueryingUtils.findNonGlobalDimensionResults(query=query) + + if count == 10: + result = [] + return result + + assert result == expectedResults + + ################################ Delete all indexes ############## def testRunAllIndexing(client, mocker): diff --git a/api/dataset/services/datasets.py b/api/dataset/services/datasets.py index fcca3f93..0496260d 100644 --- a/api/dataset/services/datasets.py +++ b/api/dataset/services/datasets.py @@ -129,7 +129,6 @@ def getDatasetData(params: dict): res = ApiResponse("Error in fetching data") try: dataset = Dataset.objects.get(id=params["datasetId"]) - # params["sql"] = params["sql"] + "some went wrong" dataDf = Data.fetchDatasetDataframe(dataset, params["sql"]) if isinstance(dataDf, str): res.update(False, "Error occured while fetching data", dataDf) diff --git a/ui/src/components/Search/Card/CardSnippet/style.module.scss b/ui/src/components/Search/Card/CardSnippet/style.module.scss index ba3fad4e..4b839a49 100644 --- a/ui/src/components/Search/Card/CardSnippet/style.module.scss +++ b/ui/src/components/Search/Card/CardSnippet/style.module.scss @@ -72,7 +72,7 @@ margin-bottom: 5px; border-radius: 10px; background: white; - height: 154px; + height: auto; padding: 10px; .chartSnippet { @@ -81,7 +81,7 @@ margin: 0; background: #aaaaaa; border-radius: 5px; - height: 134px; + height: 100%; /*border: 1px solid #aaaaaa;*/ overflow: hidden; background: white; diff --git a/ui/src/components/Search/Card/DataDisplay/Chart/index.js b/ui/src/components/Search/Card/DataDisplay/Chart/index.js index 269d4c1d..d8f4804b 100644 --- a/ui/src/components/Search/Card/DataDisplay/Chart/index.js +++ b/ui/src/components/Search/Card/DataDisplay/Chart/index.js @@ -12,6 +12,7 @@ import { G2, Guide, } from "bizcharts"; +import ErrorDisplayCard from "../../Error/ErrorDisplay"; const { Html } = Guide; track(false); @@ -37,6 +38,7 @@ class ChartCard extends React.Component { render() { const cardData = this.props.cardData; + const errorSqlMessage = this.props.errorMessage const showPercentageButton = cardData && cardData.rowsTotal; let data = []; let chartMetaData = {}; @@ -126,17 +128,25 @@ class ChartCard extends React.Component { /> {geomElements} - ) : ( -
No Data
+ ) : errorSqlMessage ?No Data
+{errorSqlMessage}
+