Support for pattern matching operators (LIKE, SIMILAR TO).
This commit is contained in:
parent
aef698bdbc
commit
938c01b9b2
3 changed files with 45 additions and 0 deletions
|
|
@ -14,6 +14,11 @@ type StringExpression interface {
|
|||
GT_EQ(rhs StringExpression) BoolExpression
|
||||
|
||||
CONCAT(rhs expression) StringExpression
|
||||
|
||||
LIKE(pattern StringExpression) BoolExpression
|
||||
NOT_LIKE(pattern StringExpression) BoolExpression
|
||||
SIMILAR_TO(pattern StringExpression) BoolExpression
|
||||
NOT_SIMILAR_TO(pattern StringExpression) BoolExpression
|
||||
}
|
||||
|
||||
type stringInterfaceImpl struct {
|
||||
|
|
@ -56,6 +61,22 @@ func (s *stringInterfaceImpl) CONCAT(rhs expression) StringExpression {
|
|||
return newBinaryStringExpression(s.parent, rhs, "||")
|
||||
}
|
||||
|
||||
func (s *stringInterfaceImpl) LIKE(pattern StringExpression) BoolExpression {
|
||||
return newBinaryBoolExpression(s.parent, pattern, "LIKE")
|
||||
}
|
||||
|
||||
func (s *stringInterfaceImpl) NOT_LIKE(pattern StringExpression) BoolExpression {
|
||||
return newBinaryBoolExpression(s.parent, pattern, "NOT LIKE")
|
||||
}
|
||||
|
||||
func (s *stringInterfaceImpl) SIMILAR_TO(pattern StringExpression) BoolExpression {
|
||||
return newBinaryBoolExpression(s.parent, pattern, "SIMILAR TO")
|
||||
}
|
||||
|
||||
func (s *stringInterfaceImpl) NOT_SIMILAR_TO(pattern StringExpression) BoolExpression {
|
||||
return newBinaryBoolExpression(s.parent, pattern, "NOT SIMILAR TO")
|
||||
}
|
||||
|
||||
//---------------------------------------------------//
|
||||
type binaryStringExpression struct {
|
||||
expressionInterfaceImpl
|
||||
|
|
|
|||
|
|
@ -45,3 +45,23 @@ func TestStringCONCAT(t *testing.T) {
|
|||
assertExpressionSerialize(t, table3StrCol.CONCAT(table2ColStr), "(table3.col2 || table2.colStr)")
|
||||
assertExpressionSerialize(t, table3StrCol.CONCAT(String("JOHN")), "(table3.col2 || $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringLIKE(t *testing.T) {
|
||||
assertExpressionSerialize(t, table3StrCol.LIKE(table2ColStr), "(table3.col2 LIKE table2.colStr)")
|
||||
assertExpressionSerialize(t, table3StrCol.LIKE(String("JOHN")), "(table3.col2 LIKE $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringNOT_LIKE(t *testing.T) {
|
||||
assertExpressionSerialize(t, table3StrCol.NOT_LIKE(table2ColStr), "(table3.col2 NOT LIKE table2.colStr)")
|
||||
assertExpressionSerialize(t, table3StrCol.NOT_LIKE(String("JOHN")), "(table3.col2 NOT LIKE $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringSIMILAR_TO(t *testing.T) {
|
||||
assertExpressionSerialize(t, table3StrCol.SIMILAR_TO(table2ColStr), "(table3.col2 SIMILAR TO table2.colStr)")
|
||||
assertExpressionSerialize(t, table3StrCol.SIMILAR_TO(String("JOHN")), "(table3.col2 SIMILAR TO $1)", "JOHN")
|
||||
}
|
||||
|
||||
func TestStringNOT_SIMILAR_TO(t *testing.T) {
|
||||
assertExpressionSerialize(t, table3StrCol.NOT_SIMILAR_TO(table2ColStr), "(table3.col2 NOT SIMILAR TO table2.colStr)")
|
||||
assertExpressionSerialize(t, table3StrCol.NOT_SIMILAR_TO(String("JOHN")), "(table3.col2 NOT SIMILAR TO $1)", "JOHN")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ func TestStringOperators(t *testing.T) {
|
|||
AllTypes.Text.LT_EQ(String("Text")),
|
||||
AllTypes.Text.CONCAT(String("text2")),
|
||||
AllTypes.Text.CONCAT(Int(11)),
|
||||
AllTypes.Text.LIKE(String("abc")),
|
||||
AllTypes.Text.NOT_LIKE(String("_b_")),
|
||||
AllTypes.Text.SIMILAR_TO(String("%(b|d)%")),
|
||||
AllTypes.Text.NOT_SIMILAR_TO(String("(b|c)%")),
|
||||
|
||||
BIT_LENGTH(AllTypes.Text),
|
||||
CHAR_LENGTH(AllTypes.Character),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue