Skip to content

Commit

Permalink
feat: add data indexing API
Browse files Browse the repository at this point in the history
  • Loading branch information
csg01123119 committed Aug 15, 2024
1 parent 06055d5 commit b8b8d1b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 25 deletions.
33 changes: 24 additions & 9 deletions lib/common/bucket/dataIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,36 @@ async function doMetaQuery(bucketName, queryParam, options = {}) {
params.content = obj2xml_1.obj2xml(paramXMLObj, { headers: true, firstUpperCase: true });
const result = await this.request(params);
const { NextToken, Files, Aggregations: aggRes } = await this.parseXML(result.data);
// console.log('Files', JSON.stringify(Files));
let files = [];
if (Files && Files.File) {
const getFileObject = item => {
const ossTagging = item.OSSTagging
? item.OSSTagging.map(tagging => ({
let ossTagging = [];
const { OSSTagging } = item;
if (OSSTagging && OSSTagging.Tagging) {
const { Tagging } = OSSTagging;
if (Tagging instanceof Array) {
ossTagging = Tagging.map(tagging => ({
key: tagging.Key,
value: tagging.Value
}))
: [];
const ossUserMeta = item.OSSUserMeta
? item.OSSUserMeta.map(meta => ({
}));
} else if (Tagging instanceof Object) {
ossTagging = [{ key: Tagging.Key, vlaue: Tagging.Value }];
}
}
let ossUserMeta = [];
const { OSSUserMeta } = item;
if (OSSUserMeta && OSSUserMeta.UserMeta) {
const { UserMeta } = OSSUserMeta;
if (UserMeta instanceof Array) {
ossUserMeta = UserMeta.map(meta => ({
key: meta.Key,
value: meta.Value
}))
: [];
}));
} else if (UserMeta instanceof Object) {
ossUserMeta = [{ key: UserMeta.Key, vlaue: UserMeta.Value }];
}
}
return {
fileName: item.Filename,
size: item.Size,
Expand All @@ -91,7 +106,7 @@ async function doMetaQuery(bucketName, queryParam, options = {}) {
ossStorageClass: item.OSSStorageClass,
objectACL: item.ObjectACL,
eTag: item.ETag,
ossTaggingCount: item.OSSTaggingCount,
ossTaggingCount: item.OSSTaggingCount || 0,
ossTagging,
ossUserMeta,
ossCRC64: item.OSSCRC64,
Expand Down
36 changes: 26 additions & 10 deletions lib/common/bucket/dataIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,38 @@ export async function doMetaQuery(this: any, bucketName: string, queryParam: IMe
const result = await this.request(params);

const { NextToken, Files, Aggregations: aggRes } = await this.parseXML(result.data);

// console.log('Files', JSON.stringify(Files));
let files: any[] = [];
if (Files && Files.File) {
const getFileObject = item => {
const ossTagging = item.OSSTagging
? item.OSSTagging.map(tagging => ({
let ossTagging: any[] = [];
const { OSSTagging } = item;
if (OSSTagging && OSSTagging.Tagging) {
const { Tagging } = OSSTagging;
if (Tagging instanceof Array) {
ossTagging = Tagging.map(tagging => ({
key: tagging.Key,
value: tagging.Value
}))
: [];
const ossUserMeta = item.OSSUserMeta
? item.OSSUserMeta.map(meta => ({
}));
} else if (Tagging instanceof Object) {
ossTagging = [{ key: Tagging.Key, vlaue: Tagging.Value }];
}
}

let ossUserMeta: any[] = [];
const { OSSUserMeta } = item;
if (OSSUserMeta && OSSUserMeta.UserMeta) {
const { UserMeta } = OSSUserMeta;
if (UserMeta instanceof Array) {
ossUserMeta = UserMeta.map(meta => ({
key: meta.Key,
value: meta.Value
}))
: [];
}));
} else if (UserMeta instanceof Object) {
ossUserMeta = [{ key: UserMeta.Key, vlaue: UserMeta.Value }];
}
}

return {
fileName: item.Filename,
size: item.Size,
Expand All @@ -131,7 +147,7 @@ export async function doMetaQuery(this: any, bucketName: string, queryParam: IMe
ossStorageClass: item.OSSStorageClass,
objectACL: item.ObjectACL,
eTag: item.ETag,
ossTaggingCount: item.OSSTaggingCount,
ossTaggingCount: item.OSSTaggingCount || 0,
ossTagging,
ossUserMeta,
ossCRC64: item.OSSCRC64,
Expand Down
43 changes: 37 additions & 6 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ describe('test/bucket.test.js', () => {
[
{
authorizationV4: false
},
{
authorizationV4: true
}
// {
// authorizationV4: true
// }
].forEach((moreConfigs, idx) => {
describe(`test bucket in iterate ${idx}`, () => {
before(async () => {
Expand Down Expand Up @@ -1680,11 +1680,42 @@ describe('test/bucket.test.js', () => {
assert(result.aggregations[1].field, 'OSSTaggingCount');
});

it('closeMetaQuery()', async () => {
const result = await store.closeMetaQuery(sts.bucket);
it.only('doMetaQuery() three Aggregations', async () => {
const queryParam = {
maxResults: 12,
query: {
operation: 'and',
subQueries: [
// { field: 'Filename', value: 'test-', operation: 'match' },
{ field: 'Size', value: '3111', operation: 'gt' }
]
},
aggregations: [
// { field: 'ETag', operation: 'count' }
// { field: 'FileModifiedTime', operation: 'distinct' },
// { field: 'Filename', operation: 'group' },
// { field: 'ObjectACL', operation: 'group' },
// { field: 'OSSCRC64', operation: 'distinct' },
// { field: 'OSSStorageClass', operation: 'group' },
// { field: 'OSSTaggingCount', operation: 'max' },
// { field: 'ServerSideEncryption', operation: 'group' },
// { field: 'Size', operation: 'sum' }
]
};

const result = await store.doMetaQuery(sts.bucket, queryParam);
console.log('result::', result.aggregations, result.files); // result.res.data.toString(),
assert.strictEqual(result.status, 200);
await utils.sleep(sleepTime * 2);
// assert(result.aggregations.length > 0);
// assert(result.aggregations[0].field, 'Size');
// assert(result.aggregations[1].field, 'OSSTaggingCount');
});

// it('closeMetaQuery()', async () => {
// const result = await store.closeMetaQuery(sts.bucket);
// assert.strictEqual(result.status, 200);
// await utils.sleep(sleepTime * 2);
// });
});
});
});
Expand Down

0 comments on commit b8b8d1b

Please sign in to comment.