|
| 1 | +/* eslint-disable no-warning-comments */ |
| 2 | + |
| 3 | +// Copyright 2019 Google LLC |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +/** |
| 20 | + * This application demonstrates how to create an Entry Group and a fileset |
| 21 | + * Entry with the Cloud Data Catalog API. |
| 22 | +
|
| 23 | + * For more information, see the README.md under /datacatalog and the |
| 24 | + * documentation at https://cloud.google.com/data-catalog/docs. |
| 25 | + */ |
| 26 | +const main = async ( |
| 27 | + projectId = process.env.GCLOUD_PROJECT, |
| 28 | + entryGroupId, |
| 29 | + entryId |
| 30 | +) => { |
| 31 | + // [START datacatalog_create_fileset_quickstart_tag] |
| 32 | + // ------------------------------- |
| 33 | + // Import required modules. |
| 34 | + // ------------------------------- |
| 35 | + const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; |
| 36 | + const datacatalog = new DataCatalogClient(); |
| 37 | + |
| 38 | + // ------------------------------- |
| 39 | + // Currently, Data Catalog stores metadata in the |
| 40 | + // us-central1 region. |
| 41 | + // ------------------------------- |
| 42 | + const location = 'us-central1'; |
| 43 | + |
| 44 | + // TODO(developer): Uncomment the following lines before running the sample. |
| 45 | + // const projectId = 'my-project' |
| 46 | + // const entryGroupId = 'my-entry-group' |
| 47 | + // const entryId = 'my-entry' |
| 48 | + |
| 49 | + // ------------------------------- |
| 50 | + // 1. Create an Entry Group. |
| 51 | + // ------------------------------- |
| 52 | + // Construct the EntryGroup for the EntryGroup request. |
| 53 | + const entryGroup = { |
| 54 | + displayName: 'My Fileset Entry Group', |
| 55 | + description: 'This Entry Group consists of ...', |
| 56 | + }; |
| 57 | + |
| 58 | + // Construct the EntryGroup request to be sent by the client. |
| 59 | + const entryGroupRequest = { |
| 60 | + parent: datacatalog.locationPath(projectId, location), |
| 61 | + entryGroupId: entryGroupId, |
| 62 | + entryGroup: entryGroup, |
| 63 | + }; |
| 64 | + |
| 65 | + // Use the client to send the API request. |
| 66 | + await datacatalog.createEntryGroup(entryGroupRequest); |
| 67 | + |
| 68 | + // ------------------------------- |
| 69 | + // 2. Create a Fileset Entry. |
| 70 | + // ------------------------------- |
| 71 | + // Construct the Entry for the Entry request. |
| 72 | + const FILESET_TYPE = 4; |
| 73 | + |
| 74 | + const entry = { |
| 75 | + displayName: 'My Fileset', |
| 76 | + description: 'This fileset consists of ...', |
| 77 | + gcsFilesetSpec: {filePatterns: ['gs://my_bucket/*']}, |
| 78 | + schema: { |
| 79 | + columns: [ |
| 80 | + { |
| 81 | + column: 'city', |
| 82 | + description: 'City', |
| 83 | + mode: 'NULLABLE', |
| 84 | + type: 'STRING', |
| 85 | + }, |
| 86 | + { |
| 87 | + column: 'state', |
| 88 | + description: 'State', |
| 89 | + mode: 'NULLABLE', |
| 90 | + type: 'STRING', |
| 91 | + }, |
| 92 | + { |
| 93 | + column: 'addresses', |
| 94 | + description: 'Addresses', |
| 95 | + mode: 'REPEATED', |
| 96 | + subcolumns: [ |
| 97 | + { |
| 98 | + column: 'city', |
| 99 | + description: 'City', |
| 100 | + mode: 'NULLABLE', |
| 101 | + type: 'STRING', |
| 102 | + }, |
| 103 | + { |
| 104 | + column: 'state', |
| 105 | + description: 'State', |
| 106 | + mode: 'NULLABLE', |
| 107 | + type: 'STRING', |
| 108 | + }, |
| 109 | + ], |
| 110 | + type: 'RECORD', |
| 111 | + }, |
| 112 | + ], |
| 113 | + }, |
| 114 | + type: FILESET_TYPE, |
| 115 | + }; |
| 116 | + |
| 117 | + // Construct the Entry request to be sent by the client. |
| 118 | + const request = { |
| 119 | + parent: datacatalog.entryGroupPath(projectId, location, entryGroupId), |
| 120 | + entryId: entryId, |
| 121 | + entry: entry, |
| 122 | + }; |
| 123 | + |
| 124 | + // Use the client to send the API request. |
| 125 | + const [response] = await datacatalog.createEntry(request); |
| 126 | + |
| 127 | + console.log(response); |
| 128 | +}; |
| 129 | +// [END datacatalog_create_fileset_quickstart_tag] |
| 130 | + |
| 131 | +// node createFilesetEntry.js <projectId> <entryGroupId> <entryId> |
| 132 | +main(...process.argv.slice(2)); |
0 commit comments