2222import com .amazonaws .athena .connector .lambda .domain .predicate .Constraints ;
2323import com .amazonaws .athena .connectors .jdbc .manager .TypeAndValue ;
2424import org .apache .arrow .vector .types .DateUnit ;
25+ import org .apache .arrow .vector .types .FloatingPointPrecision ;
26+ import org .apache .arrow .vector .types .TimeUnit ;
2527import org .apache .arrow .vector .types .pojo .ArrowType ;
2628import org .apache .arrow .vector .types .pojo .Field ;
2729import org .apache .arrow .vector .types .pojo .FieldType ;
@@ -68,28 +70,6 @@ void testGetPartitionWhereClauses() {
6870 assertTrue (result .isEmpty ());
6971 }
7072
71- // @Test
72- // void testBuildSqlString_NoConstraints() throws SQLException {
73- // Schema tableSchema = new Schema(List.of(new Field("id", new FieldType(true, new ArrowType.Int(32, true), null), null)));
74- //
75- // Constraints constraints = mock(Constraints.class);
76- // when(constraints.getLimit()).thenReturn(0L);
77- //
78- // String sql = queryBuilder.buildSqlString(mockConnection, null, "public", "users", tableSchema, constraints, null);
79- // assertTrue(sql.contains("SELECT \"id\" FROM \"public\".\"users\" "));
80- // }
81-
82- // @Test
83- // void testBuildSqlString_WithConstraints() throws SQLException {
84- // Schema tableSchema = new Schema(List.of(new Field("id", new FieldType(true, new ArrowType.Int(32, true), null), null)));
85- //
86- // Constraints constraints = mock(Constraints.class);
87- // when(constraints.getLimit()).thenReturn(10L);
88- //
89- // String sql = queryBuilder.buildSqlString(mockConnection, null, "public", "users", tableSchema, constraints, null);
90- // assertTrue(sql.contains("LIMIT 10"));
91- // }
92-
9373 @ Test
9474 void testQuote () {
9575 String result = queryBuilder .quote ("users" );
@@ -101,4 +81,66 @@ void testSingleQuote() {
10181 String result = queryBuilder .singleQuote ("O'Reilly" );
10282 assertEquals ("'O''Reilly'" , result );
10383 }
84+
85+ @ Test
86+ void testExpandSql_NullInput () {
87+ String result = queryBuilder .expandSql (null , new ArrayList <>());
88+ assertEquals (null , result );
89+ }
90+
91+ @ Test
92+ void testExpandSql_NullValue () {
93+ List <TypeAndValue > accumulator = new ArrayList <>();
94+ // Skip null value test as TypeAndValue constructor doesn't allow null values
95+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE col = ?" , accumulator );
96+ assertEquals ("SELECT * FROM table WHERE col = ?" , result );
97+ }
98+
99+ @ Test
100+ void testExpandSql_NumberTypes () {
101+ List <TypeAndValue > accumulator = new ArrayList <>();
102+ accumulator .add (new TypeAndValue (new ArrowType .Int (32 , true ), 123 ));
103+ accumulator .add (new TypeAndValue (new ArrowType .FloatingPoint (FloatingPointPrecision .DOUBLE ), 45.67 ));
104+
105+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE col1 = ? AND col2 = ?" , accumulator );
106+ assertEquals ("SELECT * FROM table WHERE col1 = 123 AND col2 = 45.67" , result );
107+ }
108+
109+ @ Test
110+ void testExpandSql_DateDay () {
111+ List <TypeAndValue > accumulator = new ArrayList <>();
112+ accumulator .add (new TypeAndValue (new ArrowType .Date (DateUnit .DAY ), 19000L )); // Days since epoch
113+
114+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE date_col = ?" , accumulator );
115+ assertTrue (result .contains ("DATE '" ));
116+ }
117+
118+ @ Test
119+ void testExpandSql_DateMilli () {
120+ List <TypeAndValue > accumulator = new ArrayList <>();
121+ accumulator .add (new TypeAndValue (new ArrowType .Timestamp (TimeUnit .MILLISECOND , null ), 1642464000000L )); // Millis since epoch
122+
123+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE timestamp_col = ?" , accumulator );
124+ // The timestamp gets converted to string format, not TIMESTAMP literal
125+ assertTrue (result .contains ("'1642464000000'" ));
126+ }
127+
128+ @ Test
129+ void testExpandSql_TimestampTypes () {
130+ List <TypeAndValue > accumulator = new ArrayList <>();
131+ accumulator .add (new TypeAndValue (new ArrowType .Timestamp (TimeUnit .MILLISECOND , "UTC" ), 1642464000000L ));
132+ accumulator .add (new TypeAndValue (new ArrowType .Timestamp (TimeUnit .MICROSECOND , "UTC" ), new java .sql .Timestamp (1642464000000L )));
133+
134+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE ts1 = ? AND ts2 = ?" , accumulator );
135+ assertTrue (result .contains ("TIMESTAMP '" ));
136+ }
137+
138+ @ Test
139+ void testExpandSql_StringValue () {
140+ List <TypeAndValue > accumulator = new ArrayList <>();
141+ accumulator .add (new TypeAndValue (new ArrowType .Utf8 (), "test'value" ));
142+
143+ String result = queryBuilder .expandSql ("SELECT * FROM table WHERE str_col = ?" , accumulator );
144+ assertEquals ("SELECT * FROM table WHERE str_col = 'test''value'" , result );
145+ }
104146}
0 commit comments