16
16
17
17
package com .google .cloud .spanner .connection .it ;
18
18
19
+ import static org .junit .Assert .assertEquals ;
20
+ import static org .junit .Assert .assertNotNull ;
19
21
22
+ import com .google .cloud .spanner .Dialect ;
20
23
import com .google .cloud .spanner .Mutation ;
21
24
import com .google .cloud .spanner .ParallelIntegrationTest ;
22
25
import com .google .cloud .spanner .ResultSet ;
23
26
import com .google .cloud .spanner .Statement ;
27
+ import com .google .cloud .spanner .connection .Connection ;
24
28
import com .google .cloud .spanner .connection .ITAbstractSpannerTest ;
25
29
import java .util .Arrays ;
30
+ import java .util .Collections ;
31
+ import org .junit .Before ;
32
+ import org .junit .BeforeClass ;
26
33
import org .junit .Test ;
27
34
import org .junit .experimental .categories .Category ;
28
35
import org .junit .runner .RunWith ;
@@ -36,9 +43,27 @@ public void appendConnectionUri(StringBuilder uri) {
36
43
uri .append (";autocommit=false" );
37
44
}
38
45
39
- @ Override
40
- public boolean doCreateDefaultTestTable () {
41
- return true ;
46
+ @ BeforeClass
47
+ public static void setupPostgreSQL (){
48
+ database = env .getTestHelper ().createTestDatabase (Dialect .POSTGRESQL , Collections .emptyList ());;
49
+ }
50
+
51
+
52
+ @ Before
53
+ public void createTestTable () {
54
+
55
+ try (Connection connection = createConnection ()) {
56
+ connection .setAutocommit (true );
57
+ if (!tableExists (connection , "TEST" )) {
58
+ connection .setAutocommit (false );
59
+ connection .startBatchDdl ();
60
+ connection .execute (
61
+ Statement .of (
62
+ "CREATE TABLE TEST (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(100) NOT NULL)" ));
63
+ connection .runBatch ();
64
+ }
65
+ }
66
+
42
67
}
43
68
44
69
@ Test
@@ -52,6 +77,30 @@ public void testExplainStatement() {
52
77
53
78
ResultSet resultSet =
54
79
connection .execute (Statement .of ("EXPLAIN SELECT * from TEST" )).getResultSet ();
80
+ while (resultSet .next ()){
81
+ assertNotNull (resultSet .getString ("QUERY PLAN" ));
82
+ }
83
+ assertEquals (1 , resultSet .getColumnCount ());
84
+ }
85
+ }
86
+
87
+ @ Test
88
+ public void testExplainAnalyzeStatement () {
89
+ try (ITConnection connection = createConnection ()) {
90
+ connection .bufferedWrite (
91
+ Arrays .asList (
92
+ Mutation .newInsertBuilder ("TEST" ).set ("ID" ).to (1L ).set ("NAME" ).to ("TEST-1" ).build (),
93
+ Mutation .newInsertBuilder ("TEST" ).set ("ID" ).to (2L ).set ("NAME" ).to ("TEST-2" ).build ()));
94
+ connection .commit ();
95
+
96
+ ResultSet resultSet =
97
+ connection .execute (Statement .of ("EXPLAIN ANALYZE SELECT * from TEST" )).getResultSet ();
98
+ while (resultSet .next ()){
99
+ assertNotNull (resultSet .getString ("QUERY PLAN" ));
100
+ assertNotNull (resultSet .getString ("EXECUTION STATS" ));
101
+ }
102
+ assertEquals (2 , resultSet .getColumnCount ());
55
103
}
56
104
}
105
+
57
106
}
0 commit comments