Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Transform-V2][SqlTransform] Support Not Like Expression #5456

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.seatunnel.e2e.transform;

import org.apache.seatunnel.e2e.common.container.TestContainer;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestTemplate;
import org.testcontainers.containers.Container;

import java.io.IOException;

public class NotLikeFilterIT extends TestSuiteBase {

@TestTemplate
public void testSQLTransform(TestContainer container) throws IOException, InterruptedException {
Container.ExecResult sqlNotLikeFilter =
container.executeJob("/sql_transform/not_like_filter.conf");
Assertions.assertEquals(0, sqlNotLikeFilter.getExitCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
######
###### This config file is a demonstration of streaming processing in seatunnel config
######
env {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add license header

execution.parallelism = 1
job.mode = "BATCH"
checkpoint.interval = 10000
}

source {
FakeSource {
result_table_name = "fake"
schema = {
fields {
id = "int"
name = "string"
age = "int"
email = "string"
}
}
rows = [
{fields = [1, "Joy Ding", 20, null], kind = INSERT}
{fields = [2, "May Ding", 22, "[email protected]"], kind = INSERT}
{fields = [3, "Kin Dom", 21, "[email protected]"], kind = INSERT}
]
}
}

transform {
Sql {
source_table_name = "fake"
result_table_name = "fake1"
query = "select id,name,age from fake where name not like '%Din_'"
}
}

sink {
Console {
source_table_name = "fake1"
}
Assert {
source_table_name = "fake1"
rules = {
field_rules = [
{
field_name = "name"
field_type = "string"
field_value = [
{equals_to = "Kin Dom"}
]
}
]
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private boolean likeExpr(LikeExpression likeExpression, Object[] inputFields) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(leftVal.toString());

return matcher.matches();
return matcher.matches() ^ likeExpression.isNot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split like with not like? this function is likeExpr but is is used in not like, this is strange .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to add a not like expression, because that's where the SQL engine expresses the match and mismatch logic. I'm referring to the IN expression logic

}

private Pair<Object, Object> executeComparisonOperator(
Expand Down