Skip to content

Commit

Permalink
Get rid of redundant lib/hive/Types
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <[email protected]>
  • Loading branch information
kravets-levko committed Apr 23, 2024
1 parent 1e4b730 commit 70cb121
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 88 deletions.
2 changes: 1 addition & 1 deletion lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import thrift from 'thrift';
import Int64 from 'node-int64';

import { EventEmitter } from 'events';
import TCLIService from '../thrift/TCLIService';
Expand All @@ -7,7 +8,6 @@ import IDBSQLClient, { ClientOptions, ConnectionOptions, OpenSessionRequest } fr
import IDriver from './contracts/IDriver';
import IClientContext, { ClientConfig } from './contracts/IClientContext';
import HiveDriver from './hive/HiveDriver';
import { Int64 } from './hive/Types';
import DBSQLSession from './DBSQLSession';
import IDBSQLSession from './contracts/IDBSQLSession';
import IAuthentication from './connection/contracts/IAuthentication';
Expand Down
2 changes: 1 addition & 1 deletion lib/DBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import stream from 'node:stream';
import util from 'node:util';
import { stringify, NIL } from 'uuid';
import Int64 from 'node-int64';
import fetch, { HeadersInit } from 'node-fetch';
import {
TSessionHandle,
Expand All @@ -12,7 +13,6 @@ import {
TSparkArrowTypes,
TSparkParameter,
} from '../thrift/TCLIService_types';
import { Int64 } from './hive/Types';
import IDBSQLSession, {
ExecuteStatementOptions,
TypeInfoRequest,
Expand Down
2 changes: 1 addition & 1 deletion lib/contracts/IDBSQLSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Int64 from 'node-int64';
import IOperation from './IOperation';
import Status from '../dto/Status';
import InfoValue from '../dto/InfoValue';
import { Int64 } from '../hive/Types';
import { DBSQLParameter, DBSQLParameterValue } from '../DBSQLParameter';

export type ExecuteStatementOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/dto/InfoValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Int64 from 'node-int64';
import { TGetInfoValue } from '../../thrift/TCLIService_types';
import { Int64 } from '../hive/Types';

type InfoResultType = string | number | Buffer | Int64 | null;

Expand Down
39 changes: 0 additions & 39 deletions lib/hive/Types/index.ts

This file was deleted.

21 changes: 2 additions & 19 deletions lib/result/JsonResultHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ColumnCode } from '../hive/Types';
import { TGetResultSetMetadataResp, TRowSet, TColumn, TColumnDesc } from '../../thrift/TCLIService_types';
import IClientContext from '../contracts/IClientContext';
import IResultsProvider, { ResultsProviderFetchNextOptions } from './IResultsProvider';
import { getSchemaColumns, convertThriftValue } from './utils';
import { getSchemaColumns, convertThriftValue, getColumnValue } from './utils';

export default class JsonResultHandler implements IResultsProvider<Array<any>> {
private readonly context: IClientContext;
Expand Down Expand Up @@ -59,7 +58,7 @@ export default class JsonResultHandler implements IResultsProvider<Array<any>> {

private getSchemaValues(descriptor: TColumnDesc, column?: TColumn): Array<any> {
const typeDescriptor = descriptor.typeDesc.types[0]?.primitiveEntry;
const columnValue = this.getColumnValue(column);
const columnValue = getColumnValue(column);

if (!columnValue) {
return [];
Expand All @@ -79,20 +78,4 @@ export default class JsonResultHandler implements IResultsProvider<Array<any>> {

return (byte & ofs) !== 0;
}

private getColumnValue(column?: TColumn) {
if (!column) {
return undefined;
}
return (
column[ColumnCode.binaryVal] ||
column[ColumnCode.boolVal] ||
column[ColumnCode.byteVal] ||
column[ColumnCode.doubleVal] ||
column[ColumnCode.i16Val] ||
column[ColumnCode.i32Val] ||
column[ColumnCode.i64Val] ||
column[ColumnCode.stringVal]
);
}
}
35 changes: 10 additions & 25 deletions lib/result/RowSetProvider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
TColumn,
TFetchOrientation,
TFetchResultsResp,
TOperationHandle,
TRowSet,
} from '../../thrift/TCLIService_types';
import { ColumnCode, FetchType, Int64 } from '../hive/Types';
import Int64 from 'node-int64';
import { TFetchOrientation, TFetchResultsResp, TOperationHandle, TRowSet } from '../../thrift/TCLIService_types';
import Status from '../dto/Status';
import IClientContext from '../contracts/IClientContext';
import IResultsProvider, { ResultsProviderFetchNextOptions } from './IResultsProvider';
import { getColumnValue } from './utils';

export enum FetchType {
Data = 0,
Logs = 1,
}

function checkIfOperationHasMoreRows(response: TFetchResultsResp): boolean {
if (response.hasMoreRows) {
Expand All @@ -17,23 +17,8 @@ function checkIfOperationHasMoreRows(response: TFetchResultsResp): boolean {

const columns = response.results?.columns || [];

if (columns.length === 0) {
return false;
}

const column: TColumn = columns[0];

const columnValue =
column[ColumnCode.binaryVal] ||
column[ColumnCode.boolVal] ||
column[ColumnCode.byteVal] ||
column[ColumnCode.doubleVal] ||
column[ColumnCode.i16Val] ||
column[ColumnCode.i32Val] ||
column[ColumnCode.i64Val] ||
column[ColumnCode.stringVal];

return (columnValue?.values?.length || 0) > 0;
const columnValue = getColumnValue(columns[0]);
return (columnValue?.values?.length ?? 0) > 0;
}

export default class RowSetProvider implements IResultsProvider<TRowSet | undefined> {
Expand Down
18 changes: 17 additions & 1 deletion lib/result/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
DateUnit,
RecordBatchWriter,
} from 'apache-arrow';
import { TTableSchema, TColumnDesc, TPrimitiveTypeEntry, TTypeId } from '../../thrift/TCLIService_types';
import { TTableSchema, TColumnDesc, TPrimitiveTypeEntry, TTypeId, TColumn } from '../../thrift/TCLIService_types';
import HiveDriverError from '../errors/HiveDriverError';

export interface ArrowBatch {
Expand Down Expand Up @@ -145,3 +145,19 @@ export function hiveSchemaToArrowSchema(schema?: TTableSchema): Buffer | undefin
writer.finish();
return Buffer.from(writer.toUint8Array(true));
}

export function getColumnValue(column?: TColumn) {
if (!column) {
return undefined;
}
return (
column.binaryVal ??
column.boolVal ??
column.byteVal ??
column.doubleVal ??
column.i16Val ??
column.i32Val ??
column.i64Val ??
column.stringVal
);
}

0 comments on commit 70cb121

Please sign in to comment.