@@ -778,6 +778,63 @@ TEST_F(ClientIntegrationTest, ExecuteBatchDmlFailure) {
778778 ASSERT_EQ (batch_result->stats [1 ].row_count , 1 );
779779}
780780
781+ TEST_F (ClientIntegrationTest, AnalyzeSql) {
782+ auto txn = MakeReadOnlyTransaction ();
783+ auto sql = SqlStatement (
784+ " SELECT * FROM Singers "
785+ " WHERE FirstName = 'Foo1' OR FirstName = 'Foo3'" );
786+
787+ // This returns a ExecutionPlan without executing the query.
788+ auto plan = client_->AnalyzeSql (std::move (txn), std::move (sql));
789+ ASSERT_STATUS_OK (plan);
790+ EXPECT_GT (plan->plan_nodes_size (), 0 );
791+ }
792+
793+ TEST_F (ClientIntegrationTest, ProfileQuery) {
794+ auto txn = MakeReadOnlyTransaction ();
795+ auto sql = SqlStatement (" SELECT * FROM Singers" );
796+
797+ auto rows = client_->ProfileQuery (std::move (txn), std::move (sql));
798+ // Consume all the rows to make the profile info available.
799+ for (auto const & row : rows) {
800+ ASSERT_STATUS_OK (row);
801+ }
802+
803+ auto stats = rows.ExecutionStats ();
804+ EXPECT_TRUE (stats);
805+ EXPECT_GT (stats->size (), 0 );
806+
807+ auto plan = rows.ExecutionPlan ();
808+ EXPECT_TRUE (plan);
809+ EXPECT_GT (plan->plan_nodes_size (), 0 );
810+ }
811+
812+ TEST_F (ClientIntegrationTest, ProfileDml) {
813+ auto & client = *client_;
814+ ProfileDmlResult profile_result;
815+ auto commit_result = client_->Commit (
816+ [&client, &profile_result](Transaction txn) -> StatusOr<Mutations> {
817+ auto sql = SqlStatement (
818+ " INSERT INTO Singers (SingerId, FirstName, LastName) "
819+ " VALUES(1, 'Foo1', 'Bar1')" );
820+ auto dml_profile = client.ProfileDml (std::move (txn), std::move (sql));
821+ if (!dml_profile) return dml_profile.status ();
822+ profile_result = std::move (*dml_profile);
823+ return Mutations{};
824+ });
825+ ASSERT_STATUS_OK (commit_result);
826+
827+ EXPECT_EQ (1 , profile_result.RowsModified ());
828+
829+ auto stats = profile_result.ExecutionStats ();
830+ EXPECT_TRUE (stats);
831+ EXPECT_GT (stats->size (), 0 );
832+
833+ auto plan = profile_result.ExecutionPlan ();
834+ EXPECT_TRUE (plan);
835+ EXPECT_GT (plan->plan_nodes_size (), 0 );
836+ }
837+
781838} // namespace
782839} // namespace SPANNER_CLIENT_NS
783840} // namespace spanner
0 commit comments