-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task/add create fileset entry #1525
Changes from 8 commits
5bc38cc
6e0cb28
1482141
56b38de
f767a0a
bc55414
2e4e282
dca8cee
0bd7816
c494a26
05df966
33483a5
977b0c0
5bbe060
069822d
ee15ba4
84c4d02
de15ac7
a8a2e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable no-warning-comments */ | ||
|
||
/** | ||
* Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* This application demonstrates how to create a Entry Group with the | ||
* Cloud Data Catalog API. | ||
|
||
* For more information, see the README.md under /datacatalog and the | ||
* documentation at https://cloud.google.com/data-catalog/docs. | ||
*/ | ||
const main = async (projectId = process.env.GCLOUD_PROJECT, entryGroupId) => { | ||
// [START datacatalog_create_entry_group_tag] | ||
// ------------------------------- | ||
// Import required modules. | ||
// ------------------------------- | ||
const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; | ||
const datacatalog = new DataCatalogClient(); | ||
|
||
// Currently, Data Catalog stores metadata in the | ||
// us-central1 region. | ||
const location = 'us-central1'; | ||
|
||
// TODO(developer): Uncomment the following lines before running the sample. | ||
// const projectId = 'my-project' | ||
// const entryGroupId = 'my-entry-group' | ||
|
||
// Create an Entry Group. | ||
// Construct the EntryGroup for the EntryGroup request. | ||
const entryGroup = { | ||
displayName: 'My Fileset Entry Group', | ||
description: 'This Entry Group consists of ....', | ||
}; | ||
|
||
// Construct the EntryGroup request to be sent by the client. | ||
const entryGroupRequest = { | ||
parent: datacatalog.locationPath(projectId, location), | ||
entryGroupId: entryGroupId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use shorthand notation here: const entryGroupRequest = {
parent: datacatalog.locationPath(projectId, location),
entryGroupId,
entryGroup,
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, changed. |
||
entryGroup: entryGroup, | ||
}; | ||
|
||
// Use the client to send the API request. | ||
const [response] = await datacatalog.createEntryGroup(entryGroupRequest); | ||
|
||
console.log(response); | ||
// [END datacatalog_create_entry_group_tag] | ||
}; | ||
|
||
// node createEntryGroup.js <projectId> <entryGroupId> | ||
main(...process.argv.slice(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable no-warning-comments */ | ||
|
||
/** | ||
* Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* This application demonstrates how to create a fileset Entry with the | ||
* Cloud Data Catalog API. | ||
|
||
* For more information, see the README.md under /datacatalog and the | ||
* documentation at https://cloud.google.com/data-catalog/docs. | ||
*/ | ||
const main = async ( | ||
projectId = process.env.GCLOUD_PROJECT, | ||
entryGroupId, | ||
entryId | ||
) => { | ||
// [START datacatalog_create_fileset_tag] | ||
// ------------------------------- | ||
// Import required modules. | ||
// ------------------------------- | ||
const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; | ||
const datacatalog = new DataCatalogClient(); | ||
|
||
// Currently, Data Catalog stores metadata in the | ||
// us-central1 region. | ||
const location = 'us-central1'; | ||
|
||
// TODO(developer): Uncomment the following lines before running the sample. | ||
// const projectId = 'my-project' | ||
// const entryGroupId = 'my-entry-group' | ||
// const entryId = 'my-entry' | ||
|
||
// Create a Fileset Entry. | ||
// Construct the Entry for the Entry request. | ||
const FILESET_TYPE = 4; | ||
|
||
const entry = { | ||
displayName: 'My Fileset', | ||
description: 'This fileset consists of ....', | ||
gcsFilesetSpec: {filePatterns: ['gs://my_bucket/*']}, | ||
schema: { | ||
columns: [ | ||
{ | ||
column: 'city', | ||
description: 'City', | ||
mode: 'NULLABLE', | ||
type: 'STRING', | ||
}, | ||
{ | ||
column: 'state', | ||
description: 'State', | ||
mode: 'NULLABLE', | ||
type: 'STRING', | ||
}, | ||
{ | ||
column: 'addresses', | ||
description: 'Addresses', | ||
mode: 'REPEATED', | ||
subcolumns: [ | ||
{ | ||
column: 'city', | ||
description: 'City', | ||
mode: 'NULLABLE', | ||
type: 'STRING', | ||
}, | ||
{ | ||
column: 'state', | ||
description: 'State', | ||
mode: 'NULLABLE', | ||
type: 'STRING', | ||
}, | ||
], | ||
type: 'RECORD', | ||
}, | ||
], | ||
}, | ||
type: FILESET_TYPE, | ||
}; | ||
|
||
// Construct the Entry request to be sent by the client. | ||
const request = { | ||
parent: datacatalog.entryGroupPath(projectId, location, entryGroupId), | ||
entryId: entryId, | ||
entry: entry, | ||
}; | ||
|
||
// Use the client to send the API request. | ||
const [response] = await datacatalog.createEntry(request); | ||
|
||
console.log(response); | ||
// [END datacatalog_create_fileset_tag] | ||
}; | ||
|
||
// node createFilesetEntry.js <projectId> <entryGroupId> <entryId> | ||
main(...process.argv.slice(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const assert = require('assert'); | ||
const tools = require('@google-cloud/nodejs-repo-tools'); | ||
const uuid = require('uuid'); | ||
const cwd = path.join(__dirname, '..'); | ||
|
||
const projectId = process.env.GCLOUD_PROJECT; | ||
// Use unique id to avoid conflicts between concurrent test runs | ||
const entryGroupId = `fileset_entry_group_${uuid.v4().substr(0, 8)}`; | ||
const location = 'us-central1'; | ||
|
||
const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; | ||
const datacatalog = new DataCatalogClient(); | ||
|
||
before(tools.checkCredentials); | ||
|
||
describe('createEntryGroup', () => { | ||
it('should create a entry group', async () => { | ||
const output = await tools.runAsync( | ||
`node createEntryGroup.js ${projectId} ${entryGroupId}`, | ||
cwd | ||
); | ||
const expectedName = `projects/${projectId}/locations/${location}/entryGroups/${entryGroupId}`; | ||
assert.ok(output.includes(expectedName)); | ||
}); | ||
|
||
after(async () => { | ||
const entryGroupPath = datacatalog.entryGroupPath( | ||
projectId, | ||
location, | ||
entryGroupId | ||
); | ||
await datacatalog.deleteEntryGroup({name: entryGroupPath}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const assert = require('assert'); | ||
const tools = require('@google-cloud/nodejs-repo-tools'); | ||
const uuid = require('uuid'); | ||
const cwd = path.join(__dirname, '..'); | ||
|
||
const projectId = process.env.GCLOUD_PROJECT; | ||
// Use unique id to avoid conflicts between concurrent test runs | ||
const entryGroupId = `fileset_entry_group_${uuid.v4().substr(0, 8)}`; | ||
const entryId = `fileset_entry_id_${uuid.v4().substr(0, 8)}`; | ||
const location = 'us-central1'; | ||
|
||
const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; | ||
const datacatalog = new DataCatalogClient(); | ||
|
||
before(tools.checkCredentials); | ||
|
||
describe('createFilesetEntry', () => { | ||
before(async () => { | ||
// Must create entryGroup before creating entry | ||
await tools.runAsync( | ||
`node createEntryGroup.js ${projectId} ${entryGroupId}`, | ||
cwd | ||
); | ||
}); | ||
|
||
it('should create a fileset entry', async () => { | ||
const output = await tools.runAsync( | ||
`node createFilesetEntry.js ${projectId} ${entryGroupId} ${entryId}`, | ||
cwd | ||
); | ||
const expectedLinkedResource = `//datacatalog.googleapis.com/projects/${projectId}/locations/${location}/entryGroups/${entryGroupId}/entries/${entryId}`; | ||
assert.ok(output.includes(expectedLinkedResource)); | ||
}); | ||
|
||
after(async () => { | ||
const entryPath = datacatalog.entryPath( | ||
projectId, | ||
location, | ||
entryGroupId, | ||
entryId | ||
); | ||
await datacatalog.deleteEntry({name: entryPath}); | ||
const entryGroupPath = datacatalog.entryGroupPath( | ||
projectId, | ||
location, | ||
entryGroupId | ||
); | ||
await datacatalog.deleteEntryGroup({name: entryGroupPath}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,18 +18,19 @@ | |
const path = require('path'); | ||
const assert = require('assert'); | ||
const tools = require('@google-cloud/nodejs-repo-tools'); | ||
|
||
const cwd = path.join(__dirname, '..'); | ||
const projectId = process.env.GCLOUD_PROJECT; | ||
const datasetId = process.env.GCLOUD_DATASET_ID; | ||
|
||
before(tools.checkCredentials); | ||
|
||
it('should lookup a dataset entry', async () => { | ||
const output = await tools.runAsync( | ||
`node lookupEntry.js ${projectId} ${datasetId}`, | ||
cwd | ||
); | ||
const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; | ||
assert.ok(output.includes(expectedLinkedResource)); | ||
describe('lookupEntry lookup', () => { | ||
it('should lookup a dataset entry', async () => { | ||
const projectId = process.env.GCLOUD_PUBLIC_PROJECT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not necessary to use environment variables for reading from a public dataset. Please remove these env vars from the kokoro config and use the project / dataset ID directly in this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const datasetId = process.env.GCLOUD_PUBLIC_DATASET_ID; | ||
const output = await tools.runAsync( | ||
`node lookupEntry.js ${projectId} ${datasetId}`, | ||
cwd | ||
); | ||
const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; | ||
assert.ok(output.includes(expectedLinkedResource)); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCLOUD_PROJECT
isn't a whitelisted environment variable. Please change toPROJECT
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I also added the common.cfg using one as example, please verify if it's ok.