public static String normalizeFilter(String projection, String filter) {
        if (isNullOrWhitespaceOnly(projection) || isNullOrWhitespaceOnly(filter)) {
            return filter;
        }

        SqlSelect sqlSelect = parseProjectionExpression(projection);
        if (sqlSelect.getSelectList().isEmpty()) {
            return filter;
        }

        Map<String, SqlNode> calculatedExpression = new HashMap<>();
        for (SqlNode sqlNode : sqlSelect.getSelectList()) {
            if (sqlNode instanceof SqlBasicCall) {
                SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
                if (SqlKind.AS.equals(sqlBasicCall.getOperator().kind)) {
                    List<SqlNode> operandList = sqlBasicCall.getOperandList();
                    if (operandList.size() == 2) {
                        SqlIdentifier alias = (SqlIdentifier) operandList.get(1);
                        String name = alias.names.get(alias.names.size() - 1);
                        SqlNode expression = operandList.get(0);
                        calculatedExpression.put(name, expression);
                    }
                }
            }
        }

        SqlNode sqlFilter = parseFilterExpression(filter).getWhere();
        sqlFilter = rewriteExpression(sqlFilter, calculatedExpression);
        if (sqlFilter != null) {
            return sqlFilter.toString();
        } else {
            return filter;
        }
    }
@Test
    public void testNormalizeFilter() {
        Assertions.assertThat(TransformParser.normalizeFilter("a, b, c, d", "a > 0 and b > 0"))
                .isEqualTo("`a` > 0 AND `b` > 0");
        Assertions.assertThat(TransformParser.normalizeFilter("a, b, c, d", null)).isEqualTo(null);
        Assertions.assertThat(
                        TransformParser.normalizeFilter(
                                "abs(a) as cal_a, char_length(b) as cal_b, c, d",
                                "a > 4 and cal_a > 8 and cal_b < 17 and c != d"))
                .isEqualTo("`a` > 4 AND ABS(`a`) > 8 AND CHAR_LENGTH(`b`) < 17 AND `c` <> `d`");

        Assertions.assertThat(
                        TransformParser.normalizeFilter(
                                "x, y, z, 1 - x as u, 1 - y as v, 1 - z as w",
                                "concat(u, concat(v, concat(w, x), y), z) != 10"))
                .isEqualTo(
                        "`concat`(1 - `x`, `concat`(1 - `y`, `concat`(1 - `z`, `x`), `y`), `z`) <> 10");
    }