github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/tpch_test.go (about)

     1  // Copyright 2021 - 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package plan
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"os"
    21  	"path/filepath"
    22  	"runtime"
    23  	"testing"
    24  
    25  	"github.com/matrixorigin/matrixone/pkg/sql/parsers"
    26  	"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
    27  )
    28  
    29  func Test_TPCH_Plan2(t *testing.T) {
    30  	ctx := context.TODO()
    31  
    32  	_, fn, _, _ := runtime.Caller(0)
    33  	dir := filepath.Dir(fn)
    34  
    35  	ddlf, err := os.ReadFile(dir + "/tpch/ddl.sql")
    36  	if err != nil {
    37  		t.Errorf("Cannot open ddl file, error %v", err)
    38  	}
    39  
    40  	ddls, err := parsers.Parse(ctx, dialect.MYSQL, string(ddlf), 1, 0)
    41  	if ddls == nil || err != nil {
    42  		t.Errorf("DDL Parser failed, error %v", err)
    43  	}
    44  
    45  	mock := NewEmptyMockOptimizer()
    46  	for _, ast := range ddls {
    47  		_, err := mock.Optimize(ast)
    48  		if err != nil {
    49  			t.Errorf("Optimizer failed, %v", err)
    50  		}
    51  	}
    52  
    53  	mock = NewMockOptimizer(false)
    54  	// test simple sql
    55  	qf, err := os.ReadFile(dir + "/tpch/simple.sql")
    56  	if err != nil {
    57  		t.Errorf("Cannot open queries file, error %v", err)
    58  	}
    59  	qs, err := parsers.Parse(ctx, dialect.MYSQL, string(qf), 1, 0)
    60  	if qs == nil || err != nil {
    61  		t.Errorf("Query Parser failed, error %v", err)
    62  	}
    63  	for _, ast := range qs {
    64  		_, err := mock.Optimize(ast)
    65  		if err != nil {
    66  			t.Errorf("Optimizer failed, NYI")
    67  		}
    68  	}
    69  
    70  	// test tpch query
    71  	for qn := 1; qn <= 22; qn += 1 {
    72  		qnf, err := os.ReadFile(fmt.Sprintf("%s/tpch/q%d.sql", dir, qn))
    73  		if err != nil {
    74  			t.Errorf("Cannot open file of query %d, error %v", qn, err)
    75  		}
    76  		qns, err := parsers.Parse(ctx, dialect.MYSQL, string(qnf), 1, 0)
    77  		if qns == nil || err != nil {
    78  			t.Errorf("Query %d Parser failed, error %v", qn, err)
    79  		}
    80  		for _, ast := range qns {
    81  			_, err := mock.Optimize(ast)
    82  			if err != nil {
    83  				t.Errorf("Optimizer %d failed, error %v", qn, err)
    84  			}
    85  		}
    86  	}
    87  }