Skip to content
Snippets Groups Projects
Unverified Commit 495e88a5 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

[QC] Remove unused metabase-lib (v1) utilities (#38504)

* Remove unused `clearSegments` utils

* Remove unused `clearFilters` utils

* Remove unused `clearAggregations` utils

* Remove unused `clearExpressions` utils

* Remove unused `hasValidBreakout` method from the `StructuredQuery`

The util with the same name was defined in `metabase-lib/queries/utils/`
parent ff092422
No related branches found
No related tags found
No related merge requests found
......@@ -644,13 +644,6 @@ class StructuredQuery extends AtomicQuery {
return this._updateQuery(Q.removeAggregation, arguments);
}
/**
* @returns {StructuredQuery} new query with all aggregations removed.
*/
clearAggregations(): StructuredQuery {
return this._updateQuery(Q.clearAggregations, arguments);
}
// BREAKOUTS
/**
......@@ -710,14 +703,6 @@ class StructuredQuery extends AtomicQuery {
return Boolean(this._database()?.hasFeature("nested-queries"));
}
/**
* @returns whether the current query has a valid breakout
*/
hasValidBreakout() {
const breakouts = this.breakouts();
return breakouts.length > 0 && breakouts[0].isValid();
}
/**
* @returns {StructuredQuery} new query with the provided MBQL @type {Breakout} added.
*/
......@@ -891,20 +876,6 @@ class StructuredQuery extends AtomicQuery {
return this._updateQuery(Q.removeFilter, arguments);
}
/**
* @returns {StructuredQuery} new query with all filters removed.
*/
clearFilters() {
return this._updateQuery(Q.clearFilters, arguments);
}
/**
* @returns {StructuredQuery} new query with all segment filters removed
*/
clearSegments() {
return this._updateQuery(Q.clearSegments, arguments);
}
// EXPRESSIONS
expressions = _.once((): ExpressionClause => {
return Q.getExpressions(this.legacyQuery({ useStructuredQuery: true }));
......@@ -924,26 +895,6 @@ class StructuredQuery extends AtomicQuery {
return query;
}
clearExpressions() {
let query = this._updateQuery(Q.clearExpressions, arguments);
// extra logic for removing expressions in fields clause
// TODO: push into query/expression?
for (const name of Object.keys(this.expressions())) {
const index = query._indexOfField(["expression", name]);
if (index >= 0) {
query = query.removeField(index);
}
}
if (this.isRaw() && this.sourceQuery()) {
query = query.clearFields();
}
return query;
}
_indexOfField(fieldRef) {
return this.fields().findIndex(f => _.isEqual(f, fieldRef));
}
......
import { STANDARD_AGGREGATIONS } from "metabase-lib/expressions";
import * as FieldRef from "./field-ref";
import { add, update, remove, clear } from "./util";
import { add, update, remove } from "./util";
/**
* Returns canonical list of Aggregations, i.e. with deprecated "rows" removed
......@@ -56,13 +56,6 @@ export function removeAggregation(aggregation, index) {
return getAggregationClause(remove(getAggregations(aggregation), index));
}
/**
* @deprecated use MLv2
*/
export function clearAggregations(ac) {
return getAggregationClause(clear());
}
// MISC
/**
* @deprecated use MLv2
......
......@@ -7,9 +7,6 @@ export function getExpressions(expressions = {}) {
export function addExpression(expressions = {}, name, expression) {
return { ...expressions, [name]: expression };
}
export function clearExpressions(expressions) {
return {};
}
/**
* Ensures expression's name uniqueness
......
......@@ -7,7 +7,7 @@ import {
import { getOperatorByTypeAndName } from "metabase-lib/operators/utils";
import { STRING } from "metabase-lib/types/constants";
import { isStartingFrom } from "metabase-lib/queries/utils/query-time";
import { op, args, noNullValues, add, update, remove, clear } from "./util";
import { op, args, noNullValues, add, update, remove } from "./util";
import { isValidField } from "./field-ref";
// returns canonical list of Filters
......@@ -41,13 +41,6 @@ export function updateFilter(filter, index, updatedFilter) {
export function removeFilter(filter, index) {
return getFilterClause(remove(getFilters(filter), index));
}
export function clearFilters(filter) {
return getFilterClause(clear());
}
export function clearSegments(filters) {
const newFilters = filters.filter(f => !isSegment(f));
return getFilterClause(newFilters);
}
// MISC
......
......@@ -34,12 +34,6 @@ export const updateAggregation = (query, index, aggregation) =>
export const removeAggregation = (query, index) =>
setAggregationClause(query, A.removeAggregation(query.aggregation, index));
/**
* @deprecated use MLv2
*/
export const clearAggregations = query =>
setAggregationClause(query, A.clearAggregations(query.aggregation));
/**
* @deprecated use MLv2
*/
......@@ -84,10 +78,6 @@ export const updateFilter = (query, index, filter) =>
setFilterClause(query, F.updateFilter(query.filter, index, filter));
export const removeFilter = (query, index) =>
setFilterClause(query, F.removeFilter(query.filter, index));
export const clearFilters = query =>
setFilterClause(query, F.clearFilters(query.filter));
export const clearSegments = query =>
setFilterClause(query, F.clearSegments(getFilters(query)));
export const canAddFilter = query => F.canAddFilter(query.filter);
......@@ -131,8 +121,6 @@ export const addExpression = (query, name, expression) =>
query,
E.addExpression(query.expressions, name, expression),
);
export const clearExpressions = query =>
setExpressionClause(query, E.clearExpressions(query.expressions));
// we can enforce various constraints in these functions:
......
......@@ -576,15 +576,6 @@ describe("StructuredQuery", () => {
);
});
});
describe("hasValidBreakout", () => {
it("should return false if there are no breakouts", () => {
expect(query.hasValidBreakout()).toBe(false);
});
it("should return true if there is at least one breakout", () => {
const ordersProductId = metadata.field(ORDERS.PRODUCT_ID);
expect(query.breakout(ordersProductId).hasValidBreakout()).toBe(true);
});
});
it("excludes breakout that has the same base dimension as what is already used", () => {
const breakout = [
......
......@@ -93,20 +93,6 @@ describe("Query", () => {
.toEqual({});
});
});
describe("clearAggregations", () => {
it("should remove all aggregations", () => {
expect(Query.clearAggregations({ aggregation: [["count"]] })).toEqual({});
expect(
Query.clearAggregations({
aggregation: [["count"], ["sum", ["field", 1, null]]],
}),
).toEqual({});
});
it("should remove all aggregations for deprecated form", () => {
expect(Query.clearAggregations({ aggregation: ["count"] })) // deprecated
.toEqual({});
});
});
describe("updateBreakout", () => {
it("should update the field", () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment