.
emit-value
fill-input
hide-selected
- :label="t('logStream.timezone')"
+ :label="t('logStream.timezone') + ' *'"
:display-value="`Timezone: ${timezone}`"
:rules="[(val: any) => !!val || 'Field is required!']"
class="timezone-select showLabelOnTop"
diff --git a/web/src/composables/useLogs.ts b/web/src/composables/useLogs.ts
index 85db0c7605..c4dc85663d 100644
--- a/web/src/composables/useLogs.ts
+++ b/web/src/composables/useLogs.ts
@@ -558,7 +558,6 @@ const useLogs = () => {
searchObj.data.query = query;
const parsedSQL: any = fnParsedSQL();
- console.log(parsedSQL);
if (!parsedSQL?.columns?.length) {
notificationMsg.value = "Invalid SQL Syntax";
return false;
@@ -724,6 +723,14 @@ const useLogs = () => {
}
}
+ const isNonAggregatedQuery = (parsedSQL: any = null) => {
+ return !(
+ parsedSQL?.groupby ||
+ hasAggregation(parsedSQL?.columns) ||
+ parsedSQL?.limit
+ );
+ };
+
const getQueryPartitions = async (queryReq: any) => {
// const queryReq = buildSearch();
searchObj.data.queryResults.hits = [];
@@ -741,11 +748,10 @@ const useLogs = () => {
};
const parsedSQL: any = fnParsedSQL();
+
if (
!searchObj.meta.sqlMode ||
- (searchObj.meta.sqlMode &&
- parsedSQL.groupby == null &&
- !hasAggregation(parsedSQL.columns))
+ (searchObj.meta.sqlMode && isNonAggregatedQuery(parsedSQL))
) {
const partitionQueryReq: any = {
sql: queryReq.query.sql,
@@ -1051,6 +1057,10 @@ const useLogs = () => {
// copy query request for histogram query and same for customDownload
searchObj.data.histogramQuery = JSON.parse(JSON.stringify(queryReq));
+
+ // Removing sql_mode from histogram query, as it is not required
+ delete searchObj.data.histogramQuery.query.sql_mode;
+
delete queryReq.aggs;
searchObj.data.customDownloadQueryObj = queryReq;
// get the current page detail and set it into query request
@@ -1102,18 +1112,36 @@ const useLogs = () => {
// based on pagination request, get the data
await getPaginatedData(queryReq);
+ const parsedSQL: any = fnParsedSQL();
+
if (
(searchObj.data.queryResults.aggs == undefined &&
searchObj.data.resultGrid.currentPage == 1 &&
searchObj.loadingHistogram == false &&
searchObj.meta.showHistogram == true &&
- searchObj.meta.sqlMode == false) ||
+ (!searchObj.meta.sqlMode ||
+ (searchObj.meta.sqlMode && isNonAggregatedQuery(parsedSQL)))) ||
(searchObj.loadingHistogram == false &&
searchObj.meta.showHistogram == true &&
searchObj.meta.sqlMode == false &&
searchObj.data.resultGrid.currentPage == 1)
) {
getHistogramQueryData(searchObj.data.histogramQuery);
+ } else if (searchObj.meta.sqlMode && !isNonAggregatedQuery(parsedSQL)) {
+ searchObj.data.histogram = {
+ xData: [],
+ yData: [],
+ chartParams: {
+ title: getHistogramTitle(),
+ unparsed_x_data: [],
+ timezone: "",
+ },
+ errorCode: 0,
+ errorMsg: "Histogram is not available for aggregation queries.",
+ errorDetail: "",
+ };
+ } else {
+ console.log("Histogram is not available for aggregation queries.");
}
} else {
searchObj.loading = false;
@@ -2220,38 +2248,46 @@ const useLogs = () => {
streamName: string
) => {
// Parse the SQL query into an AST
- const parsedQuery: any = parser.astify(sql);
+ try {
+ const parsedQuery: any = parser.astify(sql);
- // Check for the presence of an ORDER BY clause
- const hasOrderBy = !!(
- parsedQuery.orderby && parsedQuery.orderby.length > 0
- );
+ if (!parsedQuery.columns.length || !parsedQuery.from) {
+ return sql;
+ }
- // Check if _timestamp is in the SELECT clause if not SELECT *
- const includesTimestamp = !!parsedQuery.columns.find(
- (col: any) => col?.expr?.column === column || col?.expr?.column === "*"
- );
+ // Check for the presence of an ORDER BY clause
+ const hasOrderBy = !!(
+ parsedQuery.orderby && parsedQuery.orderby.length > 0
+ );
- // If ORDER BY is present and doesn't include _timestamp, append it
- if (!hasOrderBy) {
- // If no ORDER BY clause, add it
- parsedQuery.orderby = [
- {
- expr: {
- type: "column_ref",
- table: null,
- column: column,
+ // Check if _timestamp is in the SELECT clause if not SELECT *
+ const includesTimestamp = !!parsedQuery.columns.find(
+ (col: any) => col?.expr?.column === column || col?.expr?.column === "*"
+ );
+
+ // If ORDER BY is present and doesn't include _timestamp, append it
+ if (!hasOrderBy) {
+ // If no ORDER BY clause, add it
+ parsedQuery.orderby = [
+ {
+ expr: {
+ type: "column_ref",
+ table: null,
+ column: column,
+ },
+ type: type,
},
- type: type,
- },
- ];
- }
+ ];
+ }
- // Convert the AST back to a SQL string, replacing backtics with empty strings and table name with double quotes
- return quoteTableNameDirectly(
- parser.sqlify(parsedQuery).replace(/`/g, ""),
- streamName
- );
+ // Convert the AST back to a SQL string, replacing backtics with empty strings and table name with double quotes
+ return quoteTableNameDirectly(
+ parser.sqlify(parsedQuery).replace(/`/g, ""),
+ streamName
+ );
+ } catch (err) {
+ return sql;
+ }
};
function quoteTableNameDirectly(sql: string, streamName: string) {
diff --git a/web/src/plugins/logs/Index.vue b/web/src/plugins/logs/Index.vue
index 933e350dd8..c31e977cf0 100644
--- a/web/src/plugins/logs/Index.vue
+++ b/web/src/plugins/logs/Index.vue
@@ -500,7 +500,6 @@ export default defineComponent({
nextTick(() => {
if (
searchObj.meta.showHistogram &&
- !searchObj.meta.sqlMode &&
searchResultRef.value?.reDrawChart
) {
searchResultRef.value.reDrawChart();
@@ -521,39 +520,46 @@ export default defineComponent({
let currentQuery = searchObj.data.query;
//check if user try to applied saved views in which sql mode is enabled.
- if (currentQuery.indexOf("SELECT") >= 0) {
- return;
- }
- currentQuery = currentQuery.split("|");
- if (currentQuery.length > 1) {
- selectFields = "," + currentQuery[0].trim();
- if (currentQuery[1].trim() != "") {
- whereClause = "WHERE " + currentQuery[1].trim();
- }
- } else if (currentQuery[0].trim() != "") {
- if (currentQuery[0].trim() != "") {
- whereClause = "WHERE " + currentQuery[0].trim();
- }
- }
- searchObj.data.query =
- `SELECT [FIELD_LIST]${selectFields} FROM "` +
- searchObj.data.stream.selectedStream.value +
- `" ` +
- whereClause;
- if (
- searchObj.data.stream.interestingFieldList.length > 0 &&
- searchObj.meta.quickMode
- ) {
- searchObj.data.query = searchObj.data.query.replace(
- "[FIELD_LIST]",
- searchObj.data.stream.interestingFieldList.join(",")
- );
- } else {
- searchObj.data.query = searchObj.data.query.replace(
- "[FIELD_LIST]",
- "*"
- );
+ // Parse the query and check if it is valid
+ // It should have one column and one table
+
+ const hasSelect =
+ currentQuery.toLowerCase() === "select" ||
+ currentQuery.toLowerCase().indexOf("select ") == 0;
+
+ if (!hasSelect) {
+ currentQuery = currentQuery.split("|");
+ if (currentQuery.length > 1) {
+ selectFields = "," + currentQuery[0].trim();
+ if (currentQuery[1].trim() != "") {
+ whereClause = "WHERE " + currentQuery[1].trim();
+ }
+ } else if (currentQuery[0].trim() != "") {
+ if (currentQuery[0].trim() != "") {
+ whereClause = "WHERE " + currentQuery[0].trim();
+ }
+ }
+ searchObj.data.query =
+ `SELECT [FIELD_LIST]${selectFields} FROM "` +
+ searchObj.data.stream.selectedStream.value +
+ `" ` +
+ whereClause;
+
+ if (
+ searchObj.data.stream.interestingFieldList.length > 0 &&
+ searchObj.meta.quickMode
+ ) {
+ searchObj.data.query = searchObj.data.query.replace(
+ "[FIELD_LIST]",
+ searchObj.data.stream.interestingFieldList.join(",")
+ );
+ } else {
+ searchObj.data.query = searchObj.data.query.replace(
+ "[FIELD_LIST]",
+ "*"
+ );
+ }
}
searchObj.data.query = addOrderByToQuery(
@@ -573,7 +579,6 @@ export default defineComponent({
searchBarRef.value.udpateQuery();
}
} catch (e) {
- console.log(e);
console.log("Logs : Error in setQuery");
}
};
@@ -782,14 +787,12 @@ export default defineComponent({
},
showHistogram() {
if (
- this.searchObj.meta.showHistogram == true &&
- this.searchObj.shouldIgnoreWatcher == false
+ this.searchObj.meta.showHistogram &&
+ !this.searchObj.shouldIgnoreWatcher
) {
- if (this.searchObj.meta.sqlMode == false) {
- setTimeout(() => {
- if (this.searchResultRef) this.searchResultRef.reDrawChart();
- }, 100);
- }
+ setTimeout(() => {
+ if (this.searchResultRef) this.searchResultRef.reDrawChart();
+ }, 100);
if (this.searchObj.meta.histogramDirtyFlag == true) {
this.searchObj.meta.histogramDirtyFlag = false;
diff --git a/web/src/plugins/logs/SearchBar.vue b/web/src/plugins/logs/SearchBar.vue
index f3a247d8b3..f327e9fa06 100644
--- a/web/src/plugins/logs/SearchBar.vue
+++ b/web/src/plugins/logs/SearchBar.vue
@@ -19,16 +19,7 @@ along with this program. If not, see
.
-
diff --git a/web/src/plugins/logs/SearchResult.vue b/web/src/plugins/logs/SearchResult.vue
index c1d89cba9e..f6a695ec37 100644
--- a/web/src/plugins/logs/SearchResult.vue
+++ b/web/src/plugins/logs/SearchResult.vue
@@ -76,7 +76,7 @@ along with this program. If not, see .
.
/>
-
+
Error
while fetching histogram data.