You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: parse_clickhouse_test.go
    path of file: ./repos/erda/internal/tools/monitor/core/metric/query/es-tsql/influxql
    
    the code of the file until where you have to start completion: // Copyright (c) 2021 Terminus, Inc.
//
// Licensed 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.

package esinfluxql

import (
	"context"
	"strings"
	"testing"

	"github.com/doug-martin/goqu/v9"
	"github.com/influxdata/influxql"
	"github.com/stretchr/testify/require"

	"github.com/erda-project/erda/internal/tools/monitor/core/metric/model"
	tsql "github.com/erda-project/erda/internal/tools/monitor/core/metric/query/es-tsql"
)

func TestClickhouse(t *testing.T) {
	tests := []struct {
		name    string
		stm     string
		params  map[string]interface{}
		require func(t *testing.T, queries []tsql.Query)
	}{
		{
			name: "select * from metrics",
			stm:  "select * from metrics",
			require: func(t *testing.T, queries []tsql.Query) {

			},
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			p := New(0, 0, test.stm, false)
			if test.params != nil {
				p.SetParams(test.params)
			}
			err := p.Build()
			require.NoError(t, err)
			queries, err := p.ParseQuery(context.Background(), model.ClickhouseKind)
			require.NoError(t, err)
			test.require(t, queries)
		})
	}

}

func TestFilterToExpr(t *testing.T) {
	tests := []struct {
		name string
		args []*model.Filter
		want string
	}{
		{
			name: "empty",
			args: nil,
			want: "SELECT * FROM \"table\"",
		},
		{
			name: "eq",
			args: []*model.Filter{
				{
					Key:      "column",
					Value:    "123",
					Operator: "=",
				},
				{
					Key:      "column",
					Value:    "123",
					Operator: "eq",
				},
				{
					Key:      "column",
					Value:    "123",
					Operator: "",
				},
			},
			want: "SELECT * FROM \"table\" WHERE ((column = '123') AND (column = '123') AND (co
    
func TestSelect(t *testing.T) {
	tests := []struct {
		name   string
		sql    string
		want   string
		params map[string]interface{}
	}{
		{
			name: "select tenant_id",
			sql:  "select tenant_id from table",
			want: "SELECT toNullable(tenant_id) AS \"tenant_id\" FROM \"table\"",
		},
		{
			name: "select column",
			sql:  "select column from table",
			want: "SELECT toNullable(number_field_values[indexOf(number_field_keys,'column')]) AS \"column\" FROM \"table\"",
		},
		{
			name: "select sum(column)",
			sql:  "select sum(column) from table",
			want: "SELECT SUM(number_field_values[indexOf(number_field_keys,'column')]) AS \"64fa1afe5a1e10fc\" FROM \"table\"",
		},
		{
			name: "select sum",
			sql:  "select sum(column)from table",
			want: "SELECT SUM(number_field_values[indexOf(number_field_keys,'column')]) AS \"64fa1afe5a1e10fc\" FROM \"table\"",
		},
		{
			name: "select distinct",
			sql:  "select DISTINCT(service_id::tag) from table",
			want: "SELECT uniqCombined(if(indexOf(tag_keys,'service_id') == 0,null,tag_values[indexOf(tag_keys,'service_id')])) AS \"2e1cf76dc42cffe8\" FROM \"table\"",
		},
		{
			name: "select origin distinct",
			sql:  "select DISTINCT(timestamp) from table",
			want: "SELECT uniqCombined(timestamp) AS \"05b05e5af080d601\" FROM \"table\"",
		},
		{
			name: "select max",
			sql:  "select max(column) from table",
			want: "SELECT MAX(if(indexOf(number_field_keys,'column') == 0,null,number_field_values[indexOf(number_field_keys,'column')])) AS \"322cc30ad1d92b84\" FROM \"table\"",
		},
		{
			name: "select min",
			sql:  "select min(service_id::tag) from table",
			want: "SELECT MIN(if(indexOf(tag_keys,'service_id') == 0,null,tag_values[indexOf(tag_keys,'service_id')])) AS \"b784dcb694669c75\" FROM \"table\"",
		},
		{
			name: "select origin min",
			sql:  "select min(timestamp) from table",
			want: "SELECT MIN(timestamp) AS \"5636e73fd0aba08e\" FROM \"table\"",
		},
		{
			name: "select count",
			sql:  "select count(service_id::tag) from table",
			want: "SELECT COUNT(if(indexOf(tag_keys,'service_id') == 0,null,tag_values[indexOf(tag_keys,'service_id')])) AS \"993567cffecb105e\" FROM \"table\"",
		},
		{
			name: "select sum(if:eq)",
			sql:  "select sum(if(eq(error::tag, 'true'),elapsed_count::field,0)) from table",
			want: "SELECT SUM(if(tag_values[indexOf(tag_keys,'error')]='true',number_field_values[indexOf(number_field_keys,'elapsed_count')],0)) AS \"72e4961c054d5bb4\" FROM \"table\"",
		},
		{
			name: "select sum(if:gt)",
			sql:  "select sum(if(gt(error::tag, 100),elapsed_count::field,0)) from table",
			want: "SELECT SUM(if(tag_values[indexOf(tag_keys,'error')]>100,number_field_values[indexOf(number_field_keys,'elapsed_count')],0)) AS \"050269978f5ba682\" FROM \"table\"",
		},
		{
			name: "select sum(if:include)",
			sql:  "select sum(if(include(error::tag, '11','22','33'),elapsed_count::field,0)) from table",
			want: "SELECT SUM(if(((tag_values[indexOf(tag_keys,'error')])=('11') or (tag_values[indexOf(tag_keys,'error')])=('22') or (tag_values[indexOf(tag_keys,'error')])=('33')),number_field_values[indexOf(number_field_keys,'elapsed_count')],0)) AS \"19b1b14fbb96ec2c\" FROM \"table\"",
		},
		{
			name: "select sum(if:not_include)",
			sql:  "select sum(if(not_include(error::tag, '11','22','33'),elapsed_count::field,0)) from table",
			want: "SELECT SUM(if(((tag_values[indexOf(tag_keys,'error')])!=('11') and (tag_values[indexOf(tag_keys,'error')])!=('22') and (tag_values[indexOf(tag_keys,'error')])!=('33')),number_field_values[indexOf(number_field_keys,'elapsed_count')],0)) AS \"c489eef269fb2d01\" FROM \"table\"",
		},
		{
			name: "select round_float(avg)",
			sql:  "select round_float(avg(committed::field), 2) from table",
			want: "SELECT AVG(if(indexOf(number_field_keys,'committed') == 0,null,number_field_values[indexOf(number_field_keys,'committed')])) AS \"cd848468318e898b\" FROM \"table\"",
		},
		{
			name: "select time diff function",
			sql:  "SELECT service_instance_id::tag,if(gt(now()-max(timestamp),300000000000),'false','true') AS state from table",
			want: "SELECT MAX(timestamp) AS \"1362043e612fc3f5\", toNullable(tag_values[indexOf(tag_keys,'service_instance_id')]) AS \"service_instance_id::tag\" FROM \"table\"",
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			p := Parser{
				ctx: &Context{},
			}
			parse := influxql.NewParser(strings.NewReader(test.sql))
			if len(test.params) > 0 {
				parse.SetParams(test.params)
			}
			q, err := parse.ParseQuery()

			require.NoError(t, err)
			selectStmt, ok := q.Statements[0].(*influxql.SelectStatement)

			expr := goqu.From("table")
			require.Truef(t, ok, "parse query is not select statement")
			expr, handler, _, err := p.parseQueryOnExpr(selectStmt.Fields, expr)

			_ = handler

			require.NoError(t, err)

			sql, _, err := expr.ToSQL()

			require.NoError(t, err)
			require.Equal(t, test.want, sql)
		})
	}
}