Skip to content

Commit

Permalink
fix(data-masking): add unit test case for select sql syntax (oceanbas…
Browse files Browse the repository at this point in the history
…e#398)

* add: unit test

* fix: unit test
  • Loading branch information
smallsheeeep committed Sep 25, 2023
1 parent 94a4d5f commit 03b2ef5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,36 @@ public void test_extract_OBMySQL_fromMultiNestingSubquery() {
Assert.assertEquals(expectLabels, actualLabels);
}

@Test
public void test_extract_OBMySQL_whereSingleCondition() {
String sql = TestColumnExtractorUtil.getTestSql(DialectType.OB_MYSQL, "where-single-condition");
LogicalTable result = obMySQLColumnExtractor.extract(obMySQLParser.parse(new StringReader(sql)));
List<String> actualLabels = getResultColumnLabels(result);
List<String> expectLabels = Arrays.asList("id", "name", "birthday", "description");
Assert.assertEquals(4, result.getColumnList().size());
Assert.assertEquals(expectLabels, actualLabels);
}

@Test
public void test_extract_OBMySQL_whereMultiCondition() {
String sql = TestColumnExtractorUtil.getTestSql(DialectType.OB_MYSQL, "where-multi-condition");
LogicalTable result = obMySQLColumnExtractor.extract(obMySQLParser.parse(new StringReader(sql)));
List<String> actualLabels = getResultColumnLabels(result);
List<String> expectLabels = Arrays.asList("id", "name", "birthday", "description");
Assert.assertEquals(4, result.getColumnList().size());
Assert.assertEquals(expectLabels, actualLabels);
}

@Test
public void test_extract_OBMySQL_whereNestingSelect() {
String sql = TestColumnExtractorUtil.getTestSql(DialectType.OB_MYSQL, "where-nesting-select");
LogicalTable result = obMySQLColumnExtractor.extract(obMySQLParser.parse(new StringReader(sql)));
List<String> actualLabels = getResultColumnLabels(result);
List<String> expectLabels = Arrays.asList("id", "name", "birthday", "description");
Assert.assertEquals(4, result.getColumnList().size());
Assert.assertEquals(expectLabels, actualLabels);
}

@Test
public void test_extract_OBMySQL_unionTwoTables() {
String sql = TestColumnExtractorUtil.getTestSql(DialectType.OB_MYSQL, "union-two-tables");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ mysql:
FROM
test_data_masking_1 t1
WHERE
t.id = (
t1.id = (
SELECT
id
FROM
test_data_masking_2
LIMIT
1
)
OR t.name IN (
OR t1.name IN (
SELECT
name
FROM
Expand Down

0 comments on commit 03b2ef5

Please sign in to comment.