22
22
import org .apache .seatunnel .shade .com .typesafe .config .ConfigValueFactory ;
23
23
24
24
import org .apache .seatunnel .api .configuration .ReadonlyConfig ;
25
+ import org .apache .seatunnel .api .table .catalog .CatalogTable ;
25
26
import org .apache .seatunnel .api .table .type .SeaTunnelRowType ;
26
27
import org .apache .seatunnel .api .table .type .SqlType ;
27
28
28
29
import org .junit .jupiter .api .Assertions ;
29
30
import org .junit .jupiter .api .Test ;
30
31
32
+ import java .util .Collections ;
33
+ import java .util .HashMap ;
34
+ import java .util .Map ;
35
+
31
36
public class MaxcomputeSourceTest {
32
37
33
38
@ Test
34
- public void prepare () {
39
+ public void testParseSchema () {
35
40
Config fields =
36
41
ConfigFactory .empty ()
37
42
.withValue ("id" , ConfigValueFactory .fromAnyRef ("int" ))
@@ -40,10 +45,40 @@ public void prepare() {
40
45
41
46
Config schema = fields .atKey ("fields" ).atKey ("schema" );
42
47
43
- MaxcomputeSource maxcomputeSource = new MaxcomputeSource (ReadonlyConfig .fromConfig (schema ));
48
+ Config root =
49
+ schema .withValue ("project" , ConfigValueFactory .fromAnyRef ("project" ))
50
+ .withValue ("table_name" , ConfigValueFactory .fromAnyRef ("test_table" ));
51
+
52
+ MaxcomputeSource maxcomputeSource = new MaxcomputeSource (ReadonlyConfig .fromConfig (root ));
44
53
45
- SeaTunnelRowType seaTunnelRowType =
46
- maxcomputeSource .getProducedCatalogTables ().get (0 ).getSeaTunnelRowType ();
54
+ CatalogTable table = maxcomputeSource .getProducedCatalogTables ().get (0 );
55
+ Assertions .assertEquals ("project.test_table" , table .getTablePath ().toString ());
56
+ SeaTunnelRowType seaTunnelRowType = table .getSeaTunnelRowType ();
47
57
Assertions .assertEquals (SqlType .INT , seaTunnelRowType .getFieldType (0 ).getSqlType ());
58
+
59
+ Map <String , Object > tableList = new HashMap <>();
60
+ Map <String , Object > schemaMap = new HashMap <>();
61
+ Map <String , Object > fieldsMap = new HashMap <>();
62
+ fieldsMap .put ("id" , "int" );
63
+ fieldsMap .put ("name" , "string" );
64
+ fieldsMap .put ("age" , "int" );
65
+ schemaMap .put ("fields" , fieldsMap );
66
+ tableList .put ("schema" , schemaMap );
67
+ tableList .put ("table_name" , "test_table2" );
68
+
69
+ root =
70
+ ConfigFactory .empty ()
71
+ .withValue ("project" , ConfigValueFactory .fromAnyRef ("project" ))
72
+ .withValue ("accessId" , ConfigValueFactory .fromAnyRef ("accessId" ))
73
+ .withValue ("accesskey" , ConfigValueFactory .fromAnyRef ("accessKey" ))
74
+ .withValue (
75
+ "table_list" ,
76
+ ConfigValueFactory .fromIterable (
77
+ Collections .singletonList (tableList )));
78
+
79
+ maxcomputeSource = new MaxcomputeSource (ReadonlyConfig .fromConfig (root ));
80
+
81
+ table = maxcomputeSource .getProducedCatalogTables ().get (0 );
82
+ Assertions .assertEquals ("project.test_table2" , table .getTablePath ().toString ());
48
83
}
49
84
}
0 commit comments