Skip to content

Commit

Permalink
Refactor issue, queryissue pkgs (#2044)
Browse files Browse the repository at this point in the history
- Move issue definitions from issue pkg into queryissue pkg
- Move IssueInstance from issue pkg into queryIssue pkg.
- Rename IssueInstance to queryIssue
- Put queryissue and queryparser under a common folder query
  • Loading branch information
makalaaneesh authored Dec 10, 2024
1 parent 9ca3f36 commit c69f443
Show file tree
Hide file tree
Showing 23 changed files with 339 additions and 311 deletions.
7 changes: 3 additions & 4 deletions yb-voyager/cmd/analyzeSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ import (

"github.com/yugabyte/yb-voyager/yb-voyager/src/callhome"
"github.com/yugabyte/yb-voyager/yb-voyager/src/cp"
"github.com/yugabyte/yb-voyager/yb-voyager/src/issue"
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/queryissue"
"github.com/yugabyte/yb-voyager/yb-voyager/src/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryissue"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/srcdb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils/sqlname"
Expand Down Expand Up @@ -605,7 +604,7 @@ var MigrationCaveatsIssues = []string{
UNSUPPORTED_DATATYPE_LIVE_MIGRATION_WITH_FF_FB,
}

func convertIssueInstanceToAnalyzeIssue(issueInstance issue.IssueInstance, fileName string, isPlPgSQLIssue bool) utils.Issue {
func convertIssueInstanceToAnalyzeIssue(issueInstance queryissue.QueryIssue, fileName string, isPlPgSQLIssue bool) utils.Issue {
issueType := UNSUPPORTED_FEATURES
switch true {
case slices.ContainsFunc(MigrationCaveatsIssues, func(i string) bool {
Expand Down
4 changes: 2 additions & 2 deletions yb-voyager/cmd/assessMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
"github.com/yugabyte/yb-voyager/yb-voyager/src/cp"
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/migassessment"
"github.com/yugabyte/yb-voyager/yb-voyager/src/queryissue"
"github.com/yugabyte/yb-voyager/yb-voyager/src/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryissue"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/srcdb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
"github.com/yugabyte/yb-voyager/yb-voyager/src/ybversion"
Expand Down
2 changes: 1 addition & 1 deletion yb-voyager/cmd/importSchemaYugabyteDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/yugabyte/yb-voyager/yb-voyager/src/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
)

Expand Down
18 changes: 0 additions & 18 deletions yb-voyager/src/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,3 @@ func (i Issue) IsFixedIn(v *ybversion.YBVersion) (bool, error) {
}
return v.GreaterThanOrEqual(minVersionFixedInSeries), nil
}

type IssueInstance struct {
Issue
ObjectType string // TABLE, FUNCTION, DML_QUERY?
ObjectName string // table name/function name/etc
SqlStatement string
Details map[string]interface{} // additional details about the issue
}

func newIssueInstance(issue Issue, objectType string, objectName string, sqlStatement string, details map[string]interface{}) IssueInstance {
return IssueInstance{
Issue: issue,
ObjectType: objectType,
ObjectName: objectName,
SqlStatement: sqlStatement,
Details: details,
}
}
8 changes: 4 additions & 4 deletions yb-voyager/src/issue/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestIssueFixedInStable(t *testing.T) {
fixedVersion, err := ybversion.NewYBVersion("2024.1.1.0")
assert.NoError(t, err)
issue := Issue{
Type: ADVISORY_LOCKS,
Type: "ADVISORY_LOCKS",
MinimumVersionsFixedIn: map[string]*ybversion.YBVersion{
ybversion.SERIES_2024_1: fixedVersion,
},
Expand All @@ -52,7 +52,7 @@ func TestIssueFixedInPreview(t *testing.T) {
fixedVersion, err := ybversion.NewYBVersion("2.21.4.5")
assert.NoError(t, err)
issue := Issue{
Type: ADVISORY_LOCKS,
Type: "ADVISORY_LOCKS",
MinimumVersionsFixedIn: map[string]*ybversion.YBVersion{
ybversion.SERIES_2_21: fixedVersion,
},
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestIssueFixedInStableOld(t *testing.T) {
assert.NoError(t, err)

issue := Issue{
Type: ADVISORY_LOCKS,
Type: "ADVISORY_LOCKS",
MinimumVersionsFixedIn: map[string]*ybversion.YBVersion{
ybversion.SERIES_2024_1: fixedVersionStable,
ybversion.SERIES_2_20: fixedVersionStableOld,
Expand All @@ -107,7 +107,7 @@ func TestIssueFixedInStableOld(t *testing.T) {

func TestIssueFixedFalseWhenMinimumNotSpecified(t *testing.T) {
issue := Issue{
Type: ADVISORY_LOCKS,
Type: "ADVISORY_LOCKS",
}

versionsToCheck := []string{"2024.1.0.0", "2.20.7.4", "2.21.1.1"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package issue
package queryissue

// Types
const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/reflect/protoreflect"

"github.com/yugabyte/yb-voyager/yb-voyager/src/queryparser"
"github.com/yugabyte/yb-voyager/yb-voyager/src/query/queryparser"
)

const (
ADVISORY_LOCKS = "Advisory Locks"
SYSTEM_COLUMNS = "System Columns"
XML_FUNCTIONS = "XML Functions"
ADVISORY_LOCKS_NAME = "Advisory Locks"
SYSTEM_COLUMNS_NAME = "System Columns"
XML_FUNCTIONS_NAME = "XML Functions"
)

// To Add a new unsupported query construct implement this interface for all possible nodes for that construct
Expand All @@ -42,10 +42,10 @@ type FuncCallDetector struct {
func NewFuncCallDetector() *FuncCallDetector {
unsupportedFuncs := make(map[string]string)
for _, fname := range unsupportedAdvLockFuncs {
unsupportedFuncs[fname] = ADVISORY_LOCKS
unsupportedFuncs[fname] = ADVISORY_LOCKS_NAME
}
for _, fname := range unsupportedXmlFunctions {
unsupportedFuncs[fname] = XML_FUNCTIONS
unsupportedFuncs[fname] = XML_FUNCTIONS_NAME
}

return &FuncCallDetector{
Expand Down Expand Up @@ -75,7 +75,7 @@ type ColumnRefDetector struct {
func NewColumnRefDetector() *ColumnRefDetector {
unsupportedColumns := make(map[string]string)
for _, colName := range unsupportedSysCols {
unsupportedColumns[colName] = SYSTEM_COLUMNS
unsupportedColumns[colName] = SYSTEM_COLUMNS_NAME
}

return &ColumnRefDetector{
Expand Down Expand Up @@ -108,7 +108,7 @@ func NewXmlExprDetector() *XmlExprDetector {
func (d *XmlExprDetector) Detect(msg protoreflect.Message) ([]string, error) {
if queryparser.GetMsgFullName(msg) == queryparser.PG_QUERY_XMLEXPR_NODE {
log.Debug("detected xml expression")
return []string{XML_FUNCTIONS}, nil
return []string{XML_FUNCTIONS_NAME}, nil
}
return nil, nil
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func NewRangeTableFuncDetector() *RangeTableFuncDetector {
func (d *RangeTableFuncDetector) Detect(msg protoreflect.Message) ([]string, error) {
if queryparser.GetMsgFullName(msg) == queryparser.PG_QUERY_RANGETABLEFUNC_NODE {
if queryparser.IsXMLTable(msg) {
return []string{XML_FUNCTIONS}, nil
return []string{XML_FUNCTIONS_NAME}, nil
}
}
return nil, nil
Expand Down
Loading

0 comments on commit c69f443

Please sign in to comment.