AlankritVerma01 commented on code in PR #45313:
URL: https://github.com/apache/superset/pull/45313#discussion_r4356865000
##########
superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:
##########
@@ -324,6 +335,103 @@ const SqlEditor: FC<Props> = ({
[ctas, database, defaultQueryLimit, dispatch, queryEditor],
);
+ const startQuery = useCallback(
+ async (
+ ctasArg = false,
+ ctas_method: (typeof CtasEnum)[keyof typeof CtasEnum] = CtasEnum.Table,
+ ) => {
+ if (!database || estimatePending.current) {
+ return;
+ }
+
+ const warningThreshold = database.cost_estimate_warning_threshold_bytes;
+ if (
+ !ctasArg &&
+ isFeatureEnabled(FeatureFlag.EstimateQueryCost) &&
+ database.backend === 'bigquery' &&
+ database.allows_cost_estimate &&
+ typeof warningThreshold === 'number' &&
+ Number.isSafeInteger(warningThreshold) &&
+ warningThreshold >= 0
+ ) {
+ const getInputs = () => {
+ const qe = getUpToDateQuery(store.getState(), queryEditor);
+ return {
+ database_id: qe.dbId,
+ catalog: qe.catalog,
+ schema: qe.schema,
+ sql: qe.selectedText || qe.sql,
+ template_params: qe.templateParams || '{}',
+ query_limit: qe.queryLimit,
+ };
+ };
+ const inputs = getInputs();
+ const isCurrent = () =>
+ mounted.current &&
+ JSON.stringify(inputs) === JSON.stringify(getInputs());
Review Comment:
Fixed. The shortcut now captures the statement without changing the
selection. Added tests for confirmation and cancellation.
##########
superset/db_engine_specs/bigquery.py:
##########
@@ -936,7 +938,10 @@ def custom_estimate_statement_cost(
query_bytes_processed / (byte_division**3), 2
)
- return {f"{byte_type} Processed": total_bytes_processed}
+ return {
+ f"{byte_type} Processed": total_bytes_processed,
+ "bytes_processed": query_bytes_processed,
Review Comment:
Fixed. Large estimates are parsed as bigint and displayed exactly. Added
parsing and display tests.
##########
superset-frontend/src/features/databases/DatabaseModal/ExtraOptions.tsx:
##########
@@ -288,6 +316,95 @@ const ExtraOptions = ({
/>
</div>
</StyledInputContainer>
+ {(db?.backend === 'bigquery' ||
+ db?.engine === 'bigquery') && (
+ <StyledInputContainer css={no_margin_bottom}>
+ <div className="input-container">
+ <Checkbox
+ id="cost_estimate_warning_enabled"
+ name="cost_estimate_warning_enabled"
+ checked={warningsEnabled}
+ disabled={!extraJson.cost_estimate_enabled}
+ onChange={onExtraInputChange}
+ >
+ {t('Enable pre-run cost warnings')}
+ </Checkbox>
+ </div>
+ {warningsEnabled && (
+ <Flex
+ vertical
+ gap="small"
+ css={{
+ marginInlineStart: theme.sizeUnit * 8,
+ marginTop: theme.sizeUnit * 2,
+ }}
+ >
+ <label
htmlFor="cost_estimate_warning_threshold_bytes">
+ {t('Warn when estimated data processed exceeds')}
+ </label>
+ <Flex gap="small">
+ <Input
+ id="cost_estimate_warning_threshold_bytes"
+ type="number"
+ min={0}
+ max={
+ Number.MAX_SAFE_INTEGER /
+ costWarningUnits[warningUnit]
+ }
+ step={warningUnit === 'Bytes' ? 1 : 'any'}
+ value={warningAmount}
+ disabled={!extraJson.cost_estimate_enabled}
+ onChange={event =>
+ updateWarningBytes(
+ event.target.value === ''
+ ? ''
+ : Number(event.target.value) *
+ costWarningUnits[warningUnit],
+ )
+ }
+ />
+ <Select
+ css={{
+ width: theme.sizeUnit * 24,
+ flexShrink: 0,
+ }}
+ ariaLabel={t('Threshold size unit')}
+ allowClear={false}
+ value={warningUnit}
+ disabled={!extraJson.cost_estimate_enabled}
+ options={Object.keys(costWarningUnits).map(
+ value => ({
+ value,
+ label: value === 'Bytes' ? t('Bytes') :
value,
+ }),
+ )}
+ onChange={unit => {
+ if (
+ typeof unit !== 'string' ||
+ !(unit in costWarningUnits)
+ ) {
+ return;
+ }
+ const selectedUnit = unit as CostWarningUnit;
+ setWarningUnit(selectedUnit);
+ if (warningAmount !== '') {
+ updateWarningBytes(
+ warningAmount *
+ costWarningUnits[selectedUnit],
+ );
+ }
Review Comment:
Fixed. Changing units only changes the display; the saved byte threshold
stays the same. Added a regression test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]