|
24 | 24 |
|
25 | 25 | import java.math.BigDecimal;
|
26 | 26 | import java.nio.charset.Charset;
|
| 27 | +import java.sql.ResultSetMetaData; |
| 28 | +import java.sql.SQLException; |
| 29 | +import java.util.List; |
| 30 | +import java.util.Map; |
27 | 31 |
|
28 | 32 | import org.apache.arrow.vector.BaseValueVector;
|
29 | 33 | import org.apache.arrow.vector.BigIntVector;
|
|
41 | 45 | import org.apache.arrow.vector.VarCharVector;
|
42 | 46 | import org.apache.arrow.vector.VectorSchemaRoot;
|
43 | 47 | import org.apache.arrow.vector.types.pojo.Field;
|
| 48 | +import org.apache.arrow.vector.types.pojo.Schema; |
44 | 49 |
|
45 | 50 | /**
|
46 | 51 | * This is a Helper class which has functionalities to read and assert the values from the given FieldVector object.
|
@@ -179,6 +184,30 @@ public static void assertFieldMetadataIsEmpty(VectorSchemaRoot schema) {
|
179 | 184 | }
|
180 | 185 | }
|
181 | 186 |
|
| 187 | + public static void assertFieldMetadataMatchesResultSetMetadata(ResultSetMetaData rsmd, Schema schema) |
| 188 | + throws SQLException { |
| 189 | + assertNotNull(schema); |
| 190 | + assertNotNull(schema.getFields()); |
| 191 | + assertNotNull(rsmd); |
| 192 | + |
| 193 | + List<Field> fields = schema.getFields(); |
| 194 | + |
| 195 | + assertEquals(rsmd.getColumnCount(), fields.size()); |
| 196 | + |
| 197 | + // Vector columns are created in the same order as ResultSet columns. |
| 198 | + for (int i = 0; i < rsmd.getColumnCount(); ++i) { |
| 199 | + Map<String, String> metadata = fields.get(i).getMetadata(); |
| 200 | + |
| 201 | + assertNotNull(metadata); |
| 202 | + assertEquals(4, metadata.size()); |
| 203 | + |
| 204 | + assertEquals(rsmd.getCatalogName(i + 1), metadata.get(Constants.SQL_CATALOG_NAME_KEY)); |
| 205 | + assertEquals(rsmd.getTableName(i + 1), metadata.get(Constants.SQL_TABLE_NAME_KEY)); |
| 206 | + assertEquals(rsmd.getColumnName(i + 1), metadata.get(Constants.SQL_COLUMN_NAME_KEY)); |
| 207 | + assertEquals(rsmd.getColumnTypeName(i + 1), metadata.get(Constants.SQL_TYPE_KEY)); |
| 208 | + } |
| 209 | + } |
| 210 | + |
182 | 211 | public static byte[] hexStringToByteArray(String s) {
|
183 | 212 | int len = s.length();
|
184 | 213 | byte[] data = new byte[len / 2];
|
|
0 commit comments