Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,26 @@ public ResultSetStats getStats() {

@Override
public Type getType() {
Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL);
return delegate.getType();
}

@Override
public int getColumnCount() {
Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL);
return delegate.getColumnCount();
}

@Override
public int getColumnIndex(String columnName) {
Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL);
return delegate.getColumnIndex(columnName);
}

@Override
public Type getColumnType(int columnIndex) {
Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL);
return delegate.getColumnType(columnIndex);
}

@Override
public Type getColumnType(String columnName) {
Preconditions.checkState(nextCalledByClient, MISSING_NEXT_CALL);
return delegate.getColumnType(columnName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ private DirectExecuteResultSet createSubject() {
public void testMethodCallBeforeNext()
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
List<String> excludedMethods =
Arrays.asList("getStats", "next", "close", "ofResultSet", "equals", "hashCode");
Arrays.asList(
"getStats",
"next",
"close",
"ofResultSet",
"equals",
"hashCode",
"getType",
"getColumnCount",
"getColumnIndex",
"getColumnType");
DirectExecuteResultSet subject = createSubject();
callMethods(subject, excludedMethods, IllegalStateException.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.connection.ITAbstractSpannerTest;
import com.google.cloud.spanner.connection.SqlScriptVerifier;
import java.math.BigInteger;
Expand Down Expand Up @@ -213,4 +214,28 @@ public void testMultipleOpenResultSets() throws InterruptedException {
rs2.close();
}
}

@Test
public void testGetMetadataFromAnalyzeQuery() {
assumeFalse("analyze query is not supported on the emulator", isUsingEmulator());
try (ITConnection connection = createConnection()) {
// Request a query plan without executing the query and verify that we can get the column
// metadata of the query without calling resultSet.next() first.
try (ResultSet resultSet =
connection.analyzeQuery(
Statement.of("SELECT number, name FROM NUMBERS"), QueryAnalyzeMode.PLAN)) {
assertEquals(2, resultSet.getColumnCount());

assertEquals(0, resultSet.getColumnIndex("number"));
assertEquals("number", resultSet.getType().getStructFields().get(0).getName());
assertEquals(Type.int64(), resultSet.getColumnType(0));
assertEquals(Type.int64(), resultSet.getColumnType("number"));

assertEquals(1, resultSet.getColumnIndex("name"));
assertEquals("name", resultSet.getType().getStructFields().get(1).getName());
assertEquals(Type.string(), resultSet.getColumnType(1));
assertEquals(Type.string(), resultSet.getColumnType("name"));
}
}
}
}