forked from databricks/databricks-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutionResultFactoryTest.java
More file actions
141 lines (125 loc) · 6.57 KB
/
Copy pathExecutionResultFactoryTest.java
File metadata and controls
141 lines (125 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.databricks.jdbc.api.impl;
import static com.databricks.jdbc.TestConstants.ARROW_BATCH_LIST;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
import com.databricks.jdbc.api.impl.arrow.ArrowStreamResult;
import com.databricks.jdbc.api.impl.volume.VolumeOperationResult;
import com.databricks.jdbc.api.internal.IDatabricksConnectionContext;
import com.databricks.jdbc.api.internal.IDatabricksStatementInternal;
import com.databricks.jdbc.dbclient.impl.common.StatementId;
import com.databricks.jdbc.exception.DatabricksSQLException;
import com.databricks.jdbc.exception.DatabricksSQLFeatureNotSupportedException;
import com.databricks.jdbc.model.client.thrift.generated.*;
import com.databricks.jdbc.model.core.ResultData;
import com.databricks.jdbc.model.core.ResultManifest;
import com.databricks.jdbc.model.core.ResultSchema;
import com.databricks.sdk.service.sql.Format;
import java.sql.SQLException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class ExecutionResultFactoryTest {
private static final StatementId STATEMENT_ID = new StatementId("statementId");
@Mock DatabricksSession session;
@Mock IDatabricksStatementInternal parentStatement;
@Mock IDatabricksConnectionContext connectionContext;
@Mock TGetResultSetMetadataResp resultSetMetadataResp;
@Mock TRowSet tRowSet;
@Mock TFetchResultsResp fetchResultsResp;
@Test
public void testGetResultSet_jsonInline() throws DatabricksSQLException {
ResultManifest manifest = new ResultManifest();
manifest.setFormat(Format.JSON_ARRAY);
ResultData data = new ResultData();
IExecutionResult result =
ExecutionResultFactory.getResultSet(data, manifest, STATEMENT_ID, session, parentStatement);
assertInstanceOf(InlineJsonResult.class, result);
}
@Test
public void testGetResultSet_externalLink() throws DatabricksSQLException {
when(connectionContext.getConnectionUuid()).thenReturn("sample-uuid");
when(connectionContext.getHttpMaxConnectionsPerRoute()).thenReturn(100);
when(session.getConnectionContext()).thenReturn(connectionContext);
when(session.getConnectionContext().getCloudFetchThreadPoolSize()).thenReturn(16);
ResultManifest manifest = new ResultManifest();
manifest.setFormat(Format.ARROW_STREAM);
manifest.setTotalChunkCount(0L);
manifest.setTotalRowCount(0L);
manifest.setSchema(new ResultSchema().setColumnCount(0L));
ResultData data = new ResultData();
IExecutionResult result =
ExecutionResultFactory.getResultSet(data, manifest, STATEMENT_ID, session, parentStatement);
assertInstanceOf(ArrowStreamResult.class, result);
}
@Test
public void testGetResultSet_volumeOperation() throws DatabricksSQLException {
when(connectionContext.getConnectionUuid()).thenReturn("sample-uuid");
when(session.getConnectionContext()).thenReturn(connectionContext);
ResultData data = new ResultData();
ResultManifest manifest =
new ResultManifest()
.setIsVolumeOperation(true)
.setFormat(Format.JSON_ARRAY)
.setTotalRowCount(1L)
.setSchema(new ResultSchema().setColumnCount(4L));
IExecutionResult result =
ExecutionResultFactory.getResultSet(data, manifest, STATEMENT_ID, session, parentStatement);
assertInstanceOf(VolumeOperationResult.class, result);
}
@Test
public void testGetResultSet_volumeOperationThriftResp() throws Exception {
when(connectionContext.getConnectionUuid()).thenReturn("sample-uuid");
when(connectionContext.getHttpMaxConnectionsPerRoute()).thenReturn(100);
when(session.getConnectionContext()).thenReturn(connectionContext);
when(fetchResultsResp.getResultSetMetadata()).thenReturn(resultSetMetadataResp);
when(resultSetMetadataResp.getResultFormat()).thenReturn(TSparkRowSetType.COLUMN_BASED_SET);
when(resultSetMetadataResp.isSetIsStagingOperation()).thenReturn(true);
when(resultSetMetadataResp.isIsStagingOperation()).thenReturn(true);
when(resultSetMetadataResp.getSchema()).thenReturn(new TTableSchema());
IExecutionResult result =
ExecutionResultFactory.getResultSet(fetchResultsResp, session, parentStatement);
assertInstanceOf(VolumeOperationResult.class, result);
}
@Test
public void testGetResultSet_thriftColumnar() throws SQLException {
when(resultSetMetadataResp.getResultFormat()).thenReturn(TSparkRowSetType.COLUMN_BASED_SET);
when(fetchResultsResp.getResultSetMetadata()).thenReturn(resultSetMetadataResp);
IExecutionResult result =
ExecutionResultFactory.getResultSet(fetchResultsResp, session, parentStatement);
assertInstanceOf(InlineJsonResult.class, result);
}
@Test
public void testGetResultSet_thriftRow() {
when(resultSetMetadataResp.getResultFormat()).thenReturn(TSparkRowSetType.ROW_BASED_SET);
when(fetchResultsResp.getResultSetMetadata()).thenReturn(resultSetMetadataResp);
assertThrows(
DatabricksSQLFeatureNotSupportedException.class,
() -> ExecutionResultFactory.getResultSet(fetchResultsResp, session, parentStatement));
}
@Test
public void testGetResultSet_thriftURL() throws SQLException {
when(connectionContext.getConnectionUuid()).thenReturn("sample-uuid");
when(resultSetMetadataResp.getResultFormat()).thenReturn(TSparkRowSetType.URL_BASED_SET);
when(fetchResultsResp.getResultSetMetadata()).thenReturn(resultSetMetadataResp);
when(fetchResultsResp.getResults()).thenReturn(tRowSet);
when(session.getConnectionContext()).thenReturn(connectionContext);
when(session.getConnectionContext().getCloudFetchThreadPoolSize()).thenReturn(16);
IExecutionResult result =
ExecutionResultFactory.getResultSet(fetchResultsResp, session, parentStatement);
assertInstanceOf(ArrowStreamResult.class, result);
}
@Test
public void testGetResultSet_thriftInlineArrow() throws SQLException {
when(connectionContext.getConnectionUuid()).thenReturn("sample-uuid");
when(resultSetMetadataResp.getResultFormat()).thenReturn(TSparkRowSetType.ARROW_BASED_SET);
when(fetchResultsResp.getResultSetMetadata()).thenReturn(resultSetMetadataResp);
when(fetchResultsResp.getResults()).thenReturn(tRowSet);
when(session.getConnectionContext()).thenReturn(connectionContext);
when(tRowSet.getArrowBatches()).thenReturn(ARROW_BATCH_LIST);
IExecutionResult result =
ExecutionResultFactory.getResultSet(fetchResultsResp, session, parentStatement);
assertInstanceOf(ArrowStreamResult.class, result);
}
}