2016-10-17 07:14:01 +03:00
|
|
|
package ast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-04-02 22:49:45 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-10-17 07:14:01 +03:00
|
|
|
)
|
|
|
|
|
2023-07-03 18:34:19 +03:00
|
|
|
func TestInspector_findTableSegments(t *testing.T) {
|
|
|
|
const q1 = `@mydb1 | .user | .uid, .username`
|
|
|
|
|
|
|
|
ast, err := buildInitialAST(t, q1)
|
2016-10-17 07:14:01 +03:00
|
|
|
require.Nil(t, err)
|
2023-04-07 11:00:49 +03:00
|
|
|
err = NewWalker(ast).AddVisitor(typeSelectorNode, narrowTblSel).Walk()
|
2016-10-17 07:14:01 +03:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2016-10-17 07:14:01 +03:00
|
|
|
|
|
|
|
segs := ast.Segments()
|
|
|
|
require.Equal(t, 3, len(segs))
|
|
|
|
|
2023-07-03 18:34:19 +03:00
|
|
|
selSegs := insp.FindTableSegments()
|
|
|
|
require.Equal(t, 1, len(selSegs), "should be 1 table segment: the tbl sel segment")
|
|
|
|
finalSelSeg, err := insp.FindFinalTableSegment()
|
2016-10-17 07:14:01 +03:00
|
|
|
require.Nil(t, err)
|
|
|
|
require.Equal(t, selSegs[0], finalSelSeg)
|
|
|
|
}
|