Skip to content

Commit

Permalink
refactor types
Browse files Browse the repository at this point in the history
Signed-off-by: ruiyi.jiang <ruiyi.jiang@zilliz.com>
  • Loading branch information
shanghaikid committed Oct 10, 2023
1 parent 3b5dd96 commit aae9936
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 342 deletions.
2 changes: 1 addition & 1 deletion milvus/MilvusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class MilvusClient extends GRPCClient {
});
} else {
const info = await this.describeIndex({ collection_name });
indexNotExist = info.status.error_code === ErrorCode.INDEX_NOT_EXIST;
indexNotExist = info.status.error_code === ErrorCode.IndexNotExist;
}

if (indexNotExist) {
Expand Down
10 changes: 10 additions & 0 deletions milvus/const/ErrorReason.ts → milvus/const/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ export const ERROR_REASONS = {
PARTITION_KEY_FIELD_MAXED_OUT: `Only ${MAX_PARTITION_KEY_FIELD_COUNT} field supports partition key. `,
IDS_REQUIRED: 'The `ids` is missing or empty.',
};

export enum ErrorCode {
SUCCESS = 'Success',
IndexNotExist = 'IndexNotExist',
UnexpectedError = 'UnexpectedError',
EmptyCollection = 'EmptyCollection',
UpsertAutoIDTrue = 'UpsertAutoIDTrue',
CollectionNotExists = 'CollectionNotExists',
IllegalArgument = 'IllegalArgument',
}
5 changes: 2 additions & 3 deletions milvus/const/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// consts
export * from './Milvus';
export * from './milvus';
export * from './limits';
export * from './defaults';
export * from './ErrorReason';
export * from './error';
export * from './client';
75 changes: 16 additions & 59 deletions milvus/const/Milvus.ts → milvus/const/milvus.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,14 @@
// error codes, not enabled yet
enum ErrorCode {
Success = 0,
UnexpectedError = 1,
ConnectFailed = 2,
PermissionDenied = 3,
CollectionNotExists = 4,
IllegalArgument = 5,
IllegalDimension = 7,
IllegalIndexType = 8,
IllegalCollectionName = 9,
IllegalTOPK = 10,
IllegalRowRecord = 11,
IllegalVectorID = 12,
IllegalSearchResult = 13,
FileNotFound = 14,
MetaFailed = 15,
CacheFailed = 16,
CannotCreateFolder = 17,
CannotCreateFile = 18,
CannotDeleteFolder = 19,
CannotDeleteFile = 20,
BuildIndexError = 21,
IllegalNLIST = 22,
IllegalMetricType = 23,
OutOfMemory = 24,
IndexNotExist = 25,
EmptyCollection = 26,
UpdateImportTaskFailure = 27,
CollectionNameNotFound = 28,
CreateCredentialFailure = 29,
UpdateCredentialFailure = 30,
DeleteCredentialFailure = 31,
GetCredentialFailure = 32,
ListCredUsersFailure = 33,
GetUserFailure = 34,
CreateRoleFailure = 35,
DropRoleFailure = 36,
OperateUserRoleFailure = 37,
SelectRoleFailure = 38,
SelectUserFailure = 39,
SelectResourceFailure = 40,
OperatePrivilegeFailure = 41,
SelectGrantFailure = 42,
RefreshPolicyInfoCacheFailure = 43,
ListPolicyFailure = 44,
NotShardLeader = 45,
NoReplicaAvailable = 46,
SegmentNotFound = 47,
ForceDeny = 48,
RateLimit = 49,
NodeIDNotMatch = 50,

// Service availability.
// NA: Not Available.
DataCoordNA = 100,

// internal error code.
DDRequestRace = 1000,
export enum IndexState {
IndexStateNone = 0,
Unissued = 1,
InProgress = 2,
Finished = 3,
Failed = 4,
}

export enum DslType {
Dsl = 0,
BoolExprV1 = 1,
}

// consistency levels enum
Expand Down Expand Up @@ -413,3 +365,8 @@ export enum LoadState {
LoadStateLoading = 'LoadStateLoading',
LoadStateLoaded = 'LoadStateLoaded',
}

export enum ShowCollectionsType {
All,
Loaded,
}
78 changes: 30 additions & 48 deletions milvus/types/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ import {
GrpcTimeOut,
TimeStamp,
TimeStampArray,
resStatusResponse,
collectionNameReq,
} from './Common';
import { CompactionState, DataType, LoadState, DataTypeMap } from '../';

import {
CompactionState,
DataType,
LoadState,
DataTypeMap,
ShowCollectionsType,
} from '../';

// returned from milvus
export interface FieldSchema {
name: string;
description: string;
Expand Down Expand Up @@ -65,11 +74,6 @@ export interface FieldType {
default_value?: number | string;
}

export enum ShowCollectionsType {
All,
Loaded,
}

export interface ShowCollectionsReq extends GrpcTimeOut {
type?: ShowCollectionsType;
collection_names?: string[];
Expand All @@ -93,43 +97,33 @@ export interface CreateCollectionReq extends GrpcTimeOut {
enableDynamicField?: boolean;
}

export interface CollectionNameReq extends GrpcTimeOut {
/**
* @param collection_name collection name string
*/
collection_name: string;
}
export interface HasCollectionReq extends CollectionNameReq {}
export interface HasCollectionReq extends collectionNameReq {}

export interface DescribeCollectionReq extends CollectionNameReq {
export interface DescribeCollectionReq extends collectionNameReq {
cache?: boolean;
}

export interface GetCollectionStatisticsReq extends CollectionNameReq {}
export interface GetCollectionStatisticsReq extends collectionNameReq {}

export interface LoadCollectionReq extends CollectionNameReq {
export interface LoadCollectionReq extends collectionNameReq {
replica_number?: number;
resource_groups?: string[];
refresh?: boolean;
}
export interface ReleaseLoadCollectionReq extends CollectionNameReq {}
export interface ReleaseLoadCollectionReq extends collectionNameReq {}

export interface DropCollectionReq extends CollectionNameReq {}
export interface DropCollectionReq extends collectionNameReq {}

export interface CreateAliasReq extends CollectionNameReq {
// alias type
export interface CreateAliasReq extends collectionNameReq {
alias: string;
}

export interface DropAliasReq extends GrpcTimeOut {
alias: string;
}
export interface AlterAliasReq extends CreateAliasReq {}

export interface AlterAliasReq extends CollectionNameReq {
alias: string;
}

export interface CompactReq extends GrpcTimeOut {
collection_name: string;
export interface CompactReq extends collectionNameReq {
timetravel?: number | string;
}

Expand All @@ -142,24 +136,18 @@ export interface GetCompactionPlansReq extends GrpcTimeOut {
}

export interface GetReplicaReq extends GrpcTimeOut {
/**
* @param collectionID collection ID
*/
collectionID: number | string;
with_shard_nodes?: boolean;
}

export interface RenameCollectionReq extends GrpcTimeOut {
collection_name: string;
export interface RenameCollectionReq extends collectionNameReq {
new_collection_name: string;
}

export interface BoolResponse {
status: ResStatus;
export interface BoolResponse extends resStatusResponse {
value: Boolean;
}
export interface CompactionResponse {
status: ResStatus;
export interface CompactionResponse extends resStatusResponse {
compactionID: string;
}

Expand Down Expand Up @@ -188,14 +176,12 @@ export interface DescribeCollectionResponse extends TimeStamp {
db_name: string;
}

export interface GetCompactionPlansResponse {
status: ResStatus;
export interface GetCompactionPlansResponse extends resStatusResponse {
state: CompactionState;
mergeInfos: { sources: string[]; target: string }[];
}

export interface GetCompactionStateResponse {
status: ResStatus;
export interface GetCompactionStateResponse extends resStatusResponse {
state: CompactionState;
executingPlanNo: string;
timeoutPlanNo: string;
Expand All @@ -207,28 +193,24 @@ export interface ShowCollectionsResponse extends TimeStampArray {
data: CollectionData[];
}

export interface StatisticsResponse {
status: ResStatus;
export interface StatisticsResponse extends resStatusResponse {
stats: KeyValuePair[];
data: { [x: string]: any };
}

export interface ReplicasResponse {
status: ResStatus;
export interface ReplicasResponse extends resStatusResponse {
replicas: ReplicaInfo[];
}

export interface GetLoadingProgressReq extends GrpcTimeOut {
collection_name: string;
partition_names?: string[];
}
export interface GetLoadingProgressResponse {
status: ResStatus;
export interface GetLoadingProgressResponse extends resStatusResponse {
progress: string;
}

export interface GetLoadStateReq extends GetLoadingProgressReq {}
export interface GetLoadStateResponse {
status: ResStatus;
export interface GetLoadStateResponse extends resStatusResponse {
state: LoadState;
}
25 changes: 12 additions & 13 deletions milvus/types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ export interface KeyValuePair {
value: string | number;
}

export enum IndexState {
IndexStateNone = 0,
Unissued = 1,
InProgress = 2,
Finished = 3,
Failed = 4,
}

export enum DslType {
Dsl = 0,
BoolExprV1 = 1,
}

interface NumberArray {
data: Number[];
}
Expand Down Expand Up @@ -57,6 +44,10 @@ export interface ResStatus {
code?: number;
}

export interface resStatusResponse {
status: ResStatus;
}

export interface TimeStamp {
created_timestamp: string; // hybrid timestamp it's milvus inside timestamp
created_utc_timestamp: string;
Expand All @@ -70,3 +61,11 @@ export interface TimeStampArray {
export interface keyValueObj {
[key: string]: string | number;
}

export interface collectionNameReq extends GrpcTimeOut {
collection_name: string;
}

export interface partitionNameReq extends collectionNameReq {
partition_name?: string;
}
Loading

0 comments on commit aae9936

Please sign in to comment.