com.databricks.jdbc.common.util.DatabricksThriftUtil Maven / Gradle / Ivy
package com.databricks.jdbc.common.util;
import static com.databricks.jdbc.common.MetadataResultConstants.NULL_STRING;
import static com.databricks.jdbc.common.util.DatabricksTypeUtil.*;
import com.databricks.jdbc.exception.DatabricksHttpException;
import com.databricks.jdbc.log.JdbcLogger;
import com.databricks.jdbc.log.JdbcLoggerFactory;
import com.databricks.jdbc.model.client.thrift.generated.*;
import com.databricks.jdbc.model.core.ExternalLink;
import com.databricks.sdk.service.sql.ColumnInfoTypeName;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class DatabricksThriftUtil {
private static final JdbcLogger LOGGER = JdbcLoggerFactory.getLogger(DatabricksThriftUtil.class);
public static final List SUCCESS_STATUS_LIST =
List.of(TStatusCode.SUCCESS_STATUS, TStatusCode.SUCCESS_WITH_INFO_STATUS);
public static TNamespace getNamespace(String catalog, String schema) {
return new TNamespace().setCatalogName(catalog).setSchemaName(schema);
}
public static String byteBufferToString(ByteBuffer buffer) {
ByteBuffer newBuffer = buffer.duplicate(); // This is to avoid a BufferUnderflowException
long sigBits = newBuffer.getLong();
return new UUID(sigBits, sigBits).toString();
}
public static ExternalLink createExternalLink(TSparkArrowResultLink chunkInfo, long chunkIndex) {
return new ExternalLink()
.setExternalLink(chunkInfo.getFileLink())
.setChunkIndex(chunkIndex)
.setExpiration(Long.toString(chunkInfo.getExpiryTime()));
}
public static void verifySuccessStatus(TStatusCode statusCode, String errorContext)
throws DatabricksHttpException {
if (!SUCCESS_STATUS_LIST.contains(statusCode)) {
String errorMessage = "Error thrift response received. " + errorContext;
LOGGER.error(errorMessage);
throw new DatabricksHttpException(errorMessage);
}
}
public static int getColumnCount(TGetResultSetMetadataResp resultManifest) {
if (resultManifest == null || resultManifest.getSchema() == null) {
return 0;
}
return resultManifest.getSchema().getColumnsSize();
}
/**
* In metadata operations, a list of singleton lists is obtained. This function extracts metadata
* values from these TColumn lists based on the data type set in the column.
*
* @param columnList the TColumn from which to extract values
* @return a singleton list of metadata result
*/
public static List> extractValues(List columnList) {
if (columnList == null) {
return new ArrayList<>(List.of(new ArrayList<>()));
}
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy