Skip to content

Commit

Permalink
Merge branch 'master' into jack/fix-dataset-saving-edge-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrag1 committed May 18, 2023
2 parents 7b01822 + 2222073 commit 53f89f3
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 81 deletions.
2 changes: 1 addition & 1 deletion helm/superset/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ maintainers:
- name: craig-rueda
email: craig@craigrueda.com
url: https://github.com/craig-rueda
version: 0.9.4
version: 0.10.0
dependencies:
- name: postgresql
version: 12.1.6
Expand Down
5 changes: 3 additions & 2 deletions helm/superset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NOTE: This file is generated by helm-docs: https://github.com/norwoodj/helm-docs

# superset

![Version: 0.9.4](https://img.shields.io/badge/Version-0.9.4-informational?style=flat-square)
![Version: 0.10.0](https://img.shields.io/badge/Version-0.10.0-informational?style=flat-square)

Apache Superset is a modern, enterprise-ready business intelligence web application

Expand Down Expand Up @@ -91,9 +91,10 @@ helm install my-superset superset/superset
| init.containerSecurityContext | object | `{}` | |
| init.createAdmin | bool | `true` | |
| init.enabled | bool | `true` | |
| init.helmHook | bool | `true` | |
| init.initContainers | list | a container waiting for postgres | List of initContainers |
| init.initscript | string | a script to create admin user and initailize roles | A Superset init script |
| init.jobAnnotations."helm.sh/hook" | string | `"post-install,post-upgrade"` | |
| init.jobAnnotations."helm.sh/hook-delete-policy" | string | `"before-hook-creation"` | |
| init.loadExamples | bool | `false` | |
| init.podAnnotations | object | `{}` | |
| init.podSecurityContext | object | `{}` | |
Expand Down
6 changes: 2 additions & 4 deletions helm/superset/templates/init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ kind: Job
metadata:
name: {{ template "superset.name" . }}-init-db
namespace: {{ .Release.Namespace }}
{{- if .Values.init.helmHook }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": "before-hook-creation"
{{- if .Values.init.jobAnnotations }}
annotations: {{- toYaml .Values.init.jobAnnotations | nindent 4 }}
{{- end }}
spec:
template:
Expand Down
4 changes: 3 additions & 1 deletion helm/superset/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ init:
- "-c"
- ". {{ .Values.configMountPath }}/superset_bootstrap.sh; . {{ .Values.configMountPath }}/superset_init.sh"
enabled: true
helmHook: true
jobAnnotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": "before-hook-creation"
loadExamples: false
createAdmin: true
adminUser:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export { getMetricOffsetsMap } from './getMetricOffsetsMap';
export { isTimeComparison } from './isTimeComparison';
export { isDerivedSeries } from './isDerivedSeries';
export { extractExtraMetrics } from './extractExtraMetrics';
export { getOriginalSeries, hasTimeOffset } from './timeOffset';
export { TIME_COMPARISON_SEPARATOR } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
QueryFormData,
ComparisonType,
} from '@superset-ui/core';
import { isString } from 'lodash';
import { hasTimeOffset } from './timeOffset';

export const isDerivedSeries = (
series: JsonObject,
Expand All @@ -33,9 +33,6 @@ export const isDerivedSeries = (
if (comparisonType !== ComparisonType.Values) {
return false;
}

const timeCompare: string[] = ensureIsArray(formData?.time_compare);
return isString(series.name)
? !!timeCompare.find(timeOffset => series.name.endsWith(timeOffset))
: false;
return hasTimeOffset(series, timeCompare);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitationsxw
* under the License.
*/
import { JsonObject } from '@superset-ui/core';
import { isString } from 'lodash';

export const hasTimeOffset = (
series: JsonObject,
timeCompare: string[],
): boolean =>
isString(series.name)
? !!timeCompare.find(
timeOffset =>
// offset is represented as <offset>, group by list
series.name.includes(`${timeOffset},`) ||
// offset is represented as <metric>__<offset>
series.name.includes(`__${timeOffset}`),
)
: false;

export const getOriginalSeries = (
seriesName: string,
timeCompare: string[],
): string => {
let result = seriesName;
timeCompare.forEach(compare => {
// offset is represented as <offset>, group by list
result = result.replace(`${compare},`, '');
// offset is represented as <metric>__<offset>
result = result.replace(`__${compare}`, '');
});
return result.trim();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { getOriginalSeries } from '@superset-ui/chart-controls';

test('returns the series name when time compare is empty', () => {
const seriesName = 'sum';
expect(getOriginalSeries(seriesName, [])).toEqual(seriesName);
});

test('returns the original series name', () => {
const seriesName = 'sum__1_month_ago';
const timeCompare = ['1_month_ago'];
expect(getOriginalSeries(seriesName, timeCompare)).toEqual('sum');
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
/* eslint-disable camelcase */
import { invert } from 'lodash';
import {
AnnotationLayer,
CategoricalColorNamespace,
Expand All @@ -32,7 +33,9 @@ import {
getXAxisLabel,
isPhysicalColumn,
isDefined,
ensureIsArray,
} from '@superset-ui/core';
import { getOriginalSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
import {
DEFAULT_FORM_DATA,
Expand Down Expand Up @@ -296,55 +299,76 @@ export default function transformProps(
formatter: formatterSecondary,
});

const array = ensureIsArray(chartProps.rawFormData?.time_compare);
const inverted = invert(verboseMap);

rawSeriesA.forEach(entry => {
const transformedSeries = transformSeries(entry, colorScale, {
area,
markerEnabled,
markerSize,
areaOpacity: opacity,
seriesType,
showValue,
stack: Boolean(stack),
yAxisIndex,
filterState,
seriesKey: entry.name,
sliceId,
queryIndex: 0,
formatter:
seriesType === EchartsTimeseriesSeriesType.Bar
? maxLabelFormatter
: formatter,
showValueIndexes: showValueIndexesA,
totalStackedValues,
thresholdValues,
});
const entryName = String(entry.name || '');
const seriesName = inverted[entryName] || entryName;
const colorScaleKey = getOriginalSeries(seriesName, array);

const transformedSeries = transformSeries(
entry,
colorScale,
colorScaleKey,
{
area,
markerEnabled,
markerSize,
areaOpacity: opacity,
seriesType,
showValue,
stack: Boolean(stack),
yAxisIndex,
filterState,
seriesKey: entry.name,
sliceId,
queryIndex: 0,
formatter:
seriesType === EchartsTimeseriesSeriesType.Bar
? maxLabelFormatter
: formatter,
showValueIndexes: showValueIndexesA,
totalStackedValues,
thresholdValues,
},
);
if (transformedSeries) series.push(transformedSeries);
});

rawSeriesB.forEach(entry => {
const transformedSeries = transformSeries(entry, colorScale, {
area: areaB,
markerEnabled: markerEnabledB,
markerSize: markerSizeB,
areaOpacity: opacityB,
seriesType: seriesTypeB,
showValue: showValueB,
stack: Boolean(stackB),
yAxisIndex: yAxisIndexB,
filterState,
seriesKey: primarySeries.has(entry.name as string)
? `${entry.name} (1)`
: entry.name,
sliceId,
queryIndex: 1,
formatter:
seriesTypeB === EchartsTimeseriesSeriesType.Bar
? maxLabelFormatterSecondary
: formatterSecondary,
showValueIndexes: showValueIndexesB,
totalStackedValues: totalStackedValuesB,
thresholdValues: thresholdValuesB,
});
const entryName = String(entry.name || '');
const seriesName = `${inverted[entryName] || entryName} (1)`;
const colorScaleKey = getOriginalSeries(seriesName, array);

const transformedSeries = transformSeries(
entry,
colorScale,
colorScaleKey,
{
area: areaB,
markerEnabled: markerEnabledB,
markerSize: markerSizeB,
areaOpacity: opacityB,
seriesType: seriesTypeB,
showValue: showValueB,
stack: Boolean(stackB),
yAxisIndex: yAxisIndexB,
filterState,
seriesKey: primarySeries.has(entry.name as string)
? `${entry.name} (1)`
: entry.name,
sliceId,
queryIndex: 1,
formatter:
seriesTypeB === EchartsTimeseriesSeriesType.Bar
? maxLabelFormatterSecondary
: formatterSecondary,
showValueIndexes: showValueIndexesB,
totalStackedValues: totalStackedValuesB,
thresholdValues: thresholdValuesB,
},
);
if (transformedSeries) series.push(transformedSeries);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
* under the License.
*/
/* eslint-disable camelcase */
import { invert } from 'lodash';
import {
AnnotationLayer,
AxisType,
CategoricalColorNamespace,
ensureIsArray,
GenericDataType,
getMetricLabel,
getNumberFormatter,
Expand All @@ -36,6 +38,7 @@ import {
} from '@superset-ui/core';
import {
extractExtraMetrics,
getOriginalSeries,
isDerivedSeries,
} from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
Expand Down Expand Up @@ -227,30 +230,43 @@ export default function transformProps(
contributionMode || isAreaExpand ? ',.0%' : yAxisFormat,
);

const array = ensureIsArray(chartProps.rawFormData?.time_compare);
const inverted = invert(verboseMap);

rawSeries.forEach(entry => {
const lineStyle = isDerivedSeries(entry, chartProps.rawFormData)
? { type: 'dashed' as ZRLineType }
: {};
const transformedSeries = transformSeries(entry, colorScale, {
area,
filterState,
seriesContexts,
markerEnabled,
markerSize,
areaOpacity: opacity,
seriesType,
stack,
formatter,
showValue,
onlyTotal,
totalStackedValues: sortedTotalValues,
showValueIndexes,
thresholdValues,
richTooltip,
sliceId,
isHorizontal,
lineStyle,
});

const entryName = String(entry.name || '');
const seriesName = inverted[entryName] || entryName;
const colorScaleKey = getOriginalSeries(seriesName, array);

const transformedSeries = transformSeries(
entry,
colorScale,
colorScaleKey,
{
area,
filterState,
seriesContexts,
markerEnabled,
markerSize,
areaOpacity: opacity,
seriesType,
stack,
formatter,
showValue,
onlyTotal,
totalStackedValues: sortedTotalValues,
showValueIndexes,
thresholdValues,
richTooltip,
sliceId,
isHorizontal,
lineStyle,
},
);
if (transformedSeries) {
if (stack === StackControlsValue.Stream) {
// bug in Echarts - `stackStrategy: 'all'` doesn't work with nulls, so we cast them to 0
Expand Down
Loading

0 comments on commit 53f89f3

Please sign in to comment.