|
| 1 | +package com.databricks.jdbc.common.util; |
| 2 | + |
| 3 | +import com.databricks.jdbc.model.client.thrift.generated.TProtocolVersion; |
| 4 | + |
| 5 | +/** |
| 6 | + * Utility class for checking Spark protocol version features. Provides methods to determine if |
| 7 | + * specific protocol features are supported. |
| 8 | + */ |
| 9 | +public final class ProtocolFeatureUtil { |
| 10 | + // Prevent instantiation |
| 11 | + private ProtocolFeatureUtil() {} |
| 12 | + |
| 13 | + /** |
| 14 | + * Checks if the given protocol version supports getting additional information in OpenSession. |
| 15 | + * |
| 16 | + * @param protocolVersion The protocol version to check |
| 17 | + * @return true if getInfos in OpenSession is supported, false otherwise |
| 18 | + */ |
| 19 | + public static boolean supportsGetInfosInOpenSession(TProtocolVersion protocolVersion) { |
| 20 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V1) >= 0; |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Checks if the given protocol version supports direct results. |
| 25 | + * |
| 26 | + * @param protocolVersion The protocol version to check |
| 27 | + * @return true if direct results are supported, false otherwise |
| 28 | + */ |
| 29 | + public static boolean supportsDirectResults(TProtocolVersion protocolVersion) { |
| 30 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V1) >= 0; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Checks if the given protocol version supports modified hasMoreRows semantics. |
| 35 | + * |
| 36 | + * @param protocolVersion The protocol version to check |
| 37 | + * @return true if modified hasMoreRows semantics are supported, false otherwise |
| 38 | + */ |
| 39 | + public static boolean supportsModifiedHasMoreRowsSemantics(TProtocolVersion protocolVersion) { |
| 40 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V1) >= 0; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Checks if the given protocol version supports cloud result fetching. |
| 45 | + * |
| 46 | + * @param protocolVersion The protocol version to check |
| 47 | + * @return true if cloud fetch is supported, false otherwise |
| 48 | + */ |
| 49 | + public static boolean supportsCloudFetch(TProtocolVersion protocolVersion) { |
| 50 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V3) >= 0; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Checks if the given protocol version supports multiple catalogs in metadata operations. |
| 55 | + * |
| 56 | + * @param protocolVersion The protocol version to check |
| 57 | + * @return true if multiple catalogs are supported, false otherwise |
| 58 | + */ |
| 59 | + public static boolean supportsMultipleCatalogs(TProtocolVersion protocolVersion) { |
| 60 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V4) >= 0; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Checks if the given protocol version supports Arrow metadata in result sets. |
| 65 | + * |
| 66 | + * @param protocolVersion The protocol version to check |
| 67 | + * @return true if Arrow metadata is supported, false otherwise |
| 68 | + */ |
| 69 | + public static boolean supportsArrowMetadata(TProtocolVersion protocolVersion) { |
| 70 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V5) >= 0; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Checks if the given protocol version supports getting result set metadata from fetch results. |
| 75 | + * |
| 76 | + * @param protocolVersion The protocol version to check |
| 77 | + * @return true if getting result set metadata from fetch is supported, false otherwise |
| 78 | + */ |
| 79 | + public static boolean supportsResultSetMetadataFromFetch(TProtocolVersion protocolVersion) { |
| 80 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V5) >= 0; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Checks if the given protocol version supports advanced Arrow types. |
| 85 | + * |
| 86 | + * @param protocolVersion The protocol version to check |
| 87 | + * @return true if advanced Arrow types are supported, false otherwise |
| 88 | + */ |
| 89 | + public static boolean supportsAdvancedArrowTypes(TProtocolVersion protocolVersion) { |
| 90 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V5) >= 0; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Checks if the given protocol version supports compressed Arrow batches. |
| 95 | + * |
| 96 | + * @param protocolVersion The protocol version to check |
| 97 | + * @return true if compressed Arrow batches are supported, false otherwise |
| 98 | + */ |
| 99 | + public static boolean supportsCompressedArrowBatches(TProtocolVersion protocolVersion) { |
| 100 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V6) >= 0; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Checks if the given protocol version supports async metadata execution. |
| 105 | + * |
| 106 | + * @param protocolVersion The protocol version to check |
| 107 | + * @return true if async metadata execution is supported, false otherwise |
| 108 | + */ |
| 109 | + public static boolean supportsAsyncMetadataExecution(TProtocolVersion protocolVersion) { |
| 110 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V6) >= 0; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Checks if the given protocol version supports result persistence mode. |
| 115 | + * |
| 116 | + * @param protocolVersion The protocol version to check |
| 117 | + * @return true if result persistence mode is supported, false otherwise |
| 118 | + */ |
| 119 | + public static boolean supportsResultPersistenceMode(TProtocolVersion protocolVersion) { |
| 120 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7) >= 0; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Checks if the given protocol version supports parameterized queries. |
| 125 | + * |
| 126 | + * @param protocolVersion The protocol version to check |
| 127 | + * @return true if parameterized queries are supported, false otherwise |
| 128 | + */ |
| 129 | + public static boolean supportsParameterizedQueries(TProtocolVersion protocolVersion) { |
| 130 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V8) >= 0; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Checks if the given protocol version supports async metadata operations. |
| 135 | + * |
| 136 | + * @param protocolVersion The protocol version to check |
| 137 | + * @return true if async metadata operations are supported, false otherwise |
| 138 | + */ |
| 139 | + public static boolean supportsAsyncMetadataOperations(TProtocolVersion protocolVersion) { |
| 140 | + return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V9) >= 0; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Checks if the given protocol version indicates a non-Databricks compute. |
| 145 | + * |
| 146 | + * @param protocolVersion The protocol version to check |
| 147 | + * @return true if this is a non-Databricks compute, false otherwise |
| 148 | + */ |
| 149 | + public static boolean isNonDatabricksCompute(TProtocolVersion protocolVersion) { |
| 150 | + return protocolVersion.compareTo(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10) <= 0; |
| 151 | + } |
| 152 | +} |
0 commit comments