You can use the Data Catalog API to create and search for
Cloud Storage fileset entries (referred to as filesets in this
document).

## Filesets

A Cloud Storage fileset is an entry within a user-created
entry group. For more information, see
[Entries and entry groups](https://docs.cloud.google.com/data-catalog/docs/entries-and-entry-groups).

It is defined by one or more
[file patterns](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries#GcsFilesetSpec.FIELDS.file_patterns)
that specify a set of one or more Cloud Storage files.


File pattern requirements:

- A file pattern must begin with `gs://bucket_name/`.
- The bucket name must follow [Cloud Storage bucket name requirements](https://docs.cloud.google.com/storage/docs/buckets#naming).
- Wildcards are allowed in the folder and file portions of file patterns, but **wildcards are not allowed in bucket names** . For examples, see:
  - [Wildcard Names](https://docs.cloud.google.com/storage/docs/wildcards)
  - [GcsFilesetSpec.filePatterns](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries#GcsFilesetSpec.FIELDS.file_patterns) API reference documentation
- A fileset must have one, and may have no more than 5, fileset patterns.

You can query Data Catalog filesets with Dataflow SQL but
only if they have a defined schema and contain only CSV files without header
rows.

## Create entry groups and filesets

Filesets must be placed within a user-created entry group. If you have not
created an entry group, first create the entry group, then create the
fileset within the entry group. You can
[set IAM policies](https://docs.cloud.google.com/data-catalog/docs/how-to/filesets#setting_iam_policies) on the entry group to
define who has access to filesets and other entries within the entry group.

> [!IMPORTANT]
> **Managing filesets** . You can list, edit, and delete filesets using the [Google Cloud CLI command line tool](https://docs.cloud.google.com/sdk/gcloud/reference/data-catalog/entries/create) or the [Data Catalog API](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries).

### Console


### Console

1. Go to the Data Catalog **Entry groups** page.

   [Go to Entry groups](https://console.cloud.google.com/dataplex/groups)
2. Click **Create entry group**.

3. Complete the **Create Entry Group** form, then click **CREATE**.

4. The **Entry group details** page opens. With the **ENTRIES** tab selected,
   click **CREATE**.

5. Complete the **Create Fileset** form.

   ![](https://docs.cloud.google.com/static/data-catalog/images/console-create-fileset.png)

   <br />

   1. To attach a schema, click **Define Schema** to open the Schema form. Click **+ ADD FIELDS** to add fields individually or toggle **Edit as
      text** in the upper right of the form to specify the fields in JSON format. ![](https://docs.cloud.google.com/static/data-catalog/images/add-fields.png) ![](https://docs.cloud.google.com/static/data-catalog/images/add-text.png)
   2. Click **Save** to save the schema.
6. Click **Create** to create the fileset.

<br />

### gcloud


### gcloud

### 1. Create an entry group

Use the
[gcloud data-catalog entry-groups create](https://docs.cloud.google.com/sdk/gcloud/reference/data-catalog/entry-groups/create) command to create an entry group with an attached schema and description.

Example:

```
gcloud data-catalog entry-groups create my_entrygroup \
    --location=us-central1
```

### 2. Create a fileset within the entry group

Use the
[gcloud data-catalog entries create](https://docs.cloud.google.com/sdk/gcloud/reference/data-catalog/entries/create)
command to create a fileset within an entry group. This Google Cloud CLI command
example, below, creates a fileset entry that includes schema of fileset data.

```
gcloud data-catalog entries create my_fileset_entry \  
    --location=us-central1 \  
    --entry-group=my_entrygroup \  
    --type=FILESET \  
    --gcs-file-patterns=gs://my-bucket/*.csv \  
    --schema-from-file=path_to_schema_file \  
    --description="Fileset description ..."
```

Flag notes:

- `--gcs-file-patterns`: See [File pattern requirements](https://docs.cloud.google.com/data-catalog/docs/how-to/filesets#file_pattern_requirements).
- `--schema-from-file`: The following sample shows the JSON format of the schema text file accepted by the `--schema-from-file` flag.

  ```sh
  [
    {
      "column": "first_name",
      "description": "First name",
      "mode": "REQUIRED",
      "type": "STRING"
    },
    {
      "column": "last_name",
      "description": "Last name",
      "mode": "REQUIRED",
      "type": "STRING"
    },
    {
      "column": "address",
      "description": "Address",
      "mode": "REPEATED",
      "type": "STRING"
    }
  ]
  ```

<br />

### Java


Before trying this sample, follow the Java setup instructions in the
[Data Catalog quickstart using
client libraries](https://docs.cloud.google.com/data-catalog/docs/reference/libraries).


For more information, see the
[Data Catalog Java API
reference documentation](https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/overview).


To authenticate to Data Catalog, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryType.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.GcsFilesetSpec.html;
    import com.google.cloud.datacatalog.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Schema.html;
    import java.io.IOException;

    // Sample to create file set entry
    public class CreateFilesetEntry {

      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "my-project-id";
        String entryGroupId = "fileset_entry_group";
        String entryId = "fileset_entry_id";
        createFilesetEntry(projectId, entryGroupId, entryId);
      }

      // Create Fileset Entry.
      public static void createFilesetEntry(String projectId, String entryGroupId, String entryId)
          throws IOException {
        // Currently, Data Catalog stores metadata in the us-central1 region.
        String location = "us-central1";

        // Initialize client that will be used to send requests. This client only needs to be created
        // once, and can be reused for multiple requests. After completing all of your requests, call
        // the "close" method on the client to safely clean up any remaining background resources.
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html dataCatalogClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html.create()) {
          // Construct the Entry for the Entry request.
          https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html entry =
              https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html.newBuilder()
                  .setDisplayName("My Fileset")
                  .setDescription("This fileset consists of ....")
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.Builder.html#com_google_cloud_datacatalog_v1_Entry_Builder_setGcsFilesetSpec_com_google_cloud_datacatalog_v1_GcsFilesetSpec_(
                      https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.GcsFilesetSpec.html.newBuilder().https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.GcsFilesetSpec.Builder.html#com_google_cloud_datacatalog_v1_GcsFilesetSpec_Builder_addFilePatterns_java_lang_String_("gs://cloud-samples-data/*").build())
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.Builder.html#com_google_cloud_datacatalog_v1_Entry_Builder_setSchema_com_google_cloud_datacatalog_v1_Schema_(
                      https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Schema.html.newBuilder()
                          .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Schema.Builder.html#com_google_cloud_datacatalog_v1_Schema_Builder_addColumns_com_google_cloud_datacatalog_v1_ColumnSchema_(
                              https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html.newBuilder()
                                  .setColumn("first_name")
                                  .setDescription("First name")
                                  .setMode("REQUIRED")
                                  .setType("STRING")
                                  .build())
                          .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Schema.Builder.html#com_google_cloud_datacatalog_v1_Schema_Builder_addColumns_com_google_cloud_datacatalog_v1_ColumnSchema_(
                              https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html.newBuilder()
                                  .setColumn("last_name")
                                  .setDescription("Last name")
                                  .setMode("REQUIRED")
                                  .setType("STRING")
                                  .build())
                          .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Schema.Builder.html#com_google_cloud_datacatalog_v1_Schema_Builder_addColumns_com_google_cloud_datacatalog_v1_ColumnSchema_(
                              https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html.newBuilder()
                                  .setColumn("addresses")
                                  .setDescription("Addresses")
                                  .setMode("REPEATED")
                                  .setType("RECORD")
                                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.Builder.html#com_google_cloud_datacatalog_v1_ColumnSchema_Builder_addSubcolumns_com_google_cloud_datacatalog_v1_ColumnSchema_(
                                      https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html.newBuilder()
                                          .setColumn("city")
                                          .setDescription("City")
                                          .setMode("NULLABLE")
                                          .setType("STRING")
                                          .build())
                                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.Builder.html#com_google_cloud_datacatalog_v1_ColumnSchema_Builder_addSubcolumns_com_google_cloud_datacatalog_v1_ColumnSchema_(
                                      https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.ColumnSchema.html.newBuilder()
                                          .setColumn("state")
                                          .setDescription("State")
                                          .setMode("NULLABLE")
                                          .setType("STRING")
                                          .build())
                                  .build())
                          .build())
                  .setType(https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryType.html.FILESET)
                  .build();

          // Construct the Entry request to be sent by the client.
          https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html entryRequest =
              https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html.newBuilder()
                  .setParent(https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html.of(projectId, location, entryGroupId).toString())
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.Builder.html#com_google_cloud_datacatalog_v1_CreateEntryRequest_Builder_setEntryId_java_lang_String_(entryId)
                  .setEntry(entry)
                  .build();

          // Use the client to send the API request.
          https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html entryCreated = dataCatalogClient.createEntry(entryRequest);
          System.out.printf("Entry created with name: %s", entryCreated.https://docs.cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html#com_google_cloud_datacatalog_v1_Entry_getName__());
        }
      }
    }

<br />

### Node.js


Before trying this sample, follow the Node.js setup instructions in the
[Data Catalog quickstart using
client libraries](https://docs.cloud.google.com/data-catalog/docs/reference/libraries).


For more information, see the
[Data Catalog Node.js API
reference documentation](https://googleapis.dev/nodejs/datacatalog/latest/index.html).


To authenticate to Data Catalog, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    // Import the Google Cloud client library.
    const {DataCatalogClient} = require('https://docs.cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html').v1;
    const datacatalog = new https://docs.cloud.google.com/nodejs/docs/reference/datacatalog/latest/overview.html();

    async function createFileset() {
      // Create a fileset within an entry group.

      /**
       * TODO(developer): Uncomment the following lines before running the sample.
       */
      // const projectId = 'my_project';
      // const entryGroupId = 'my_entry_group';
      // const entryId = 'my_entry';

      // Currently, Data Catalog stores metadata in the us-central1 region.
      const location = 'us-central1';

      // Delete any pre-existing Entry with the same name that will be used
      // when creating the new Entry.
      try {
        const formattedName = datacatalog.entryPath(
          projectId,
          location,
          entryGroupId,
          entryId
        );
        await datacatalog.deleteEntry({name: formattedName});
      } catch (err) {
        console.log('Entry does not exist.');
      }

      // Delete any pre-existing Entry Group with the same name
      // that will be used to create the new Entry Group.
      try {
        const formattedName = datacatalog.entryGroupPath(
          projectId,
          location,
          entryGroupId
        );
        await datacatalog.deleteEntryGroup({name: formattedName});
      } catch (err) {
        console.log('Entry Group does not exist.');
      }

      // Construct the Entry Group for the Entry Group request.
      const entryGroup = {
        displayName: 'My Fileset Entry Group',
        description: 'This Entry Group consists of ....',
      };

      // Construct the Entry Group request to be sent by the client.
      const entryGroupRequest = {
        parent: datacatalog.locationPath(projectId, location),
        entryGroupId: entryGroupId,
        entryGroup: entryGroup,
      };

      // Use the client to send the API request.
      await datacatalog.createEntryGroup(entryGroupRequest);

      // 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(`Name: ${response.name}`);
      console.log(`Display name: ${response.displayName}`);
      console.log(`Type: ${response.type}`);
    }
    createFileset();

<br />

### Python


Before trying this sample, follow the Python setup instructions in the
[Data Catalog quickstart using
client libraries](https://docs.cloud.google.com/data-catalog/docs/reference/libraries).


For more information, see the
[Data Catalog Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/datacatalog/latest).


To authenticate to Data Catalog, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    # Import required modules.
    from google.cloud import https://docs.cloud.google.com/python/docs/reference/datacatalog/latest

    # TODO: Set these values before running the sample.
    project_id = "project_id"
    fileset_entry_group_id = "entry_group_id"
    fileset_entry_id = "entry_id"

    # For all regions available, see:
    # https://cloud.google.com/data-catalog/docs/concepts/regions
    location = "us-central1"

    datacatalog = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html()

    # Create an Entry Group.
    entry_group_obj = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.EntryGroup.html()
    entry_group_obj.display_name = "My Fileset Entry Group"
    entry_group_obj.description = "This Entry Group consists of ...."

    entry_group = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_create_entry_group(
        parent=https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html.common_location_path(
            project_id, location
        ),
        entry_group_id=fileset_entry_group_id,
        entry_group=entry_group_obj,
    )
    print(f"Created entry group: {entry_group.name}")

    # Create a Fileset Entry.
    entry = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.Entry.html()
    entry.display_name = "My Fileset"
    entry.description = "This fileset consists of ...."
    entry.gcs_fileset_spec.file_patterns.append("gs://my_bucket/*.csv")
    entry.type_ = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.EntryType.html.FILESET

    # Create the Schema, for example when you have a csv file.
    entry.schema.columns.append(
        https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.ColumnSchema.html(
            column="first_name",
            description="First name",
            mode="REQUIRED",
            type_="STRING",
        )
    )

    entry.schema.columns.append(
        https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.ColumnSchema.html(
            column="last_name", description="Last name", mode="REQUIRED", type_="STRING"
        )
    )

    # Create the addresses parent column
    addresses_column = https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.ColumnSchema.html(
        column="addresses", description="Addresses", mode="REPEATED", type_="RECORD"
    )

    # Create sub columns for the addresses parent column
    addresses_column.subcolumns.append(
        https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.ColumnSchema.html(
            column="city", description="City", mode="NULLABLE", type_="STRING"
        )
    )

    addresses_column.subcolumns.append(
        https://docs.cloud.google.com/python/docs/reference/datacatalog/latest.types.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.types.ColumnSchema.html(
            column="state", description="State", mode="NULLABLE", type_="STRING"
        )
    )

    entry.schema.columns.append(addresses_column)

    entry = datacatalog.https://docs.cloud.google.com/python/docs/reference/datacatalog/latest/google.cloud.datacatalog_v1.services.data_catalog.DataCatalogClient.html#google_cloud_datacatalog_v1_services_data_catalog_DataCatalogClient_create_entry(
        parent=entry_group.name, entry_id=fileset_entry_id, entry=entry
    )
    print(f"Created fileset entry: {entry.name}")

<br />

### REST and Command line


### REST

If you don't have access to Cloud Client libraries for your language or
want to test the API using REST requests, see the following examples
and refer to the Data Catalog REST API
[entryGroups.create](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups/create)
and
[entryGroups.entries.create](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups.entries/create)
documentation.

1. Create an entry group


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: Your Google Cloud project ID
- <var translate="no">[entryGroupId](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups/create#body.QUERY_PARAMETERS.entry_group_id)</var>: The ID must begin with a letter or underscore, contain only English letters, numbers and underscores, and be at most 64 characters.
- <var translate="no">[displayName](https://docs.cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.entryGroups#EntryGroup.FIELDS.display_name)</var>: The textual name for the entry group.


HTTP method and URL:

```
POST https://datacatalog.googleapis.com/v1/projects/project-id/locations/region/entryGroups?entryGroupId=entryGroupId
```


Request JSON body:

```
{
  "displayName": "Entry Group display name"
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "x-goog-user-project: project-id" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://datacatalog.googleapis.com/v1/projects/project-id/locations/region/entryGroups?entryGroupId=entryGroupId"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://datacatalog.googleapis.com/v1/projects/project-id/locations/region/entryGroups?entryGroupId=entryGroupId" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "name": "projects/my_projectid/locations/us-central1/entryGroups/my_entry_group",
  "displayName": "Entry Group display name",
  "dataCatalogTimestamps": {
    "createTime": "2019-10-19T16:35:50.135Z",
    "updateTime": "2019-10-19T16:35:50.135Z"
  }
}
```

1. Create a fileset within the entry group


Before using any of the request data,
make the following replacements:

- <var translate="no">project_id</var>: Your Google Cloud project ID
- <var translate="no">entryGroupId</var>: ID of existing entryGroup. Fileset will be create in this sntryGroup.
- <var translate="no">entryId</var>: EntryId of the new fileset. ID must begin with a letter or underscore, contain only English letters, numbers and underscores, and be at most 64 characters.
- <var translate="no">description</var>: Fileset description.
- <var translate="no">displayName</var>: The textual name for the fileset entry.
- <var translate="no">filePatterns</var>: Must start with "gs://<var translate="no">bucket_name/</var>". See [File pattern requirements](https://docs.cloud.google.com/data-catalog/docs/how-to/filesets#file_pattern_requirements).
- <var translate="no">schema</var>: Fileset schema.

  <br />

  **Example JSON schema:**

  ```
  { ...
    "schema": {
      "columns": [
        {
          "column": "first_name",
          "description": "First name",
          "mode": "REQUIRED",
          "type": "STRING"
        },
        {
          "column": "last_name",
          "description": "Last name",
          "mode": "REQUIRED",
          "type": "STRING"
        },
        {
          "column": "address",
          "description": "Address",
          "mode": "REPEATED",
          "subcolumns": [
            {
              "column": "city",
              "description": "City",
              "mode": "NULLABLE",
              "type": "STRING"
            },
            {
              "column": "state",
              "description": "State",
              "mode": "NULLABLE",
              "type": "STRING"
            }
          ],
          "type": "RECORD"
        }
      ]
    }
  ...
  }
  ```


HTTP method and URL:

```
POST https://datacatalog.googleapis.com/v1/projects/project_id/locations/region/entryGroups/entryGroupId/entries?entryId=entryId
```


Request JSON body:

```
{
  "description": "Fileset description.",
  "displayName": "Display name",
  "gcsFilesetSpec": {
    "filePatterns": [
      "gs://bucket_name/file_pattern"
    ]
  },
  "type": "FILESET",
  "schema": { schema }
}

```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "x-goog-user-project: project_id" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://datacatalog.googleapis.com/v1/projects/project_id/locations/region/entryGroups/entryGroupId/entries?entryId=entryId"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project_id" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://datacatalog.googleapis.com/v1/projects/project_id/locations/region/entryGroups/entryGroupId/entries?entryId=entryId" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "name": "projects/my_project_id/locations/us-central1/entryGroups/my_entryGroup_id/entries/my_entry_id",
  "type": "FILESET",
  "displayName": "My Fileset",
  "description": "My Fileset description.",
  "schema": {
    "columns": [
      {
        "type": "STRING",
        "description": "First name",
        "mode": "REQUIRED",
        "column": "first_name"
      },
      {
        "type": "STRING",
        "description": "Last name",
        "mode": "REQUIRED",
        "column": "last_name"
      },
      {
        "type": "RECORD",
        "description": "Address",
        "mode": "REPEATED",
        "column": "address",
        "subcolumns": [
          {
            "type": "STRING",
            "description": "City",
            "mode": "NULLABLE",
            "column": "city"
          },
          {
            "type": "STRING",
            "description": "State",
            "mode": "NULLABLE",
            "column": "state"
          }
        ]
      }
    ]
  },
  "gcsFilesetSpec": {
    "filePatterns": [
      "gs://my_bucket_name/chicago_taxi_trips/csv/shard-*.csv"
    ]
  },
  "sourceSystemTimestamps": {
    "createTime": "2019-10-23T23:11:26.326Z",
    "updateTime": "2019-10-23T23:11:26.326Z"
  },
"linkedResource": "//datacatalog.googleapis.com/projects/my_project_id/locations/us-central1/entryGroups/my_entryGroup_id/entries/my_entry_id"
}
```

<br />

## IAM roles, permissions, and policies

Data Catalog defines entry and entry group roles to
facilitate permission management of filesets and other Data Catalog
resources.

| Entry roles | Description |
|---|---|
| `dataCatalog.entryOwner` | Owner of a particular entry or group of entries. - Permissions: - datacatalog.entries.(\*) - datacatalog.entryGroups.get - Applicability: - Organization, project, and entryGroup level |
| `dataCatalog.entryViewer` | Can view details of entry and entryGroup. - Permissions - datacatalog.entries.get - datacatalog.entryGroups.get - Applicability: - Organization, project, and entryGroup level |

| Entry group roles | Description |
|---|---|
| `dataCatalog.entryGroupOwner` | Owner of a particular entryGroup. - Permissions: - datacatalog.entryGroups.(\*) - datacatalog entries.(\*) - Applicability: - Organization, project, and entryGroup level |
| `dataCatalog.entryGroupCreator` | Can create entryGroups within a project. The creator of an entryGroup is automatically granted the `dataCatalog.entryGroupOwner` role. - Permissions: - datacatalog.entryGroups.(get \| create) - Applicability: - Organization and project level |

### Set IAM policies

Users with `datacatalog.<resource>.setIamPolicy` permission
can set IAM policies on Data Catalog entry groups
and other Data Catalog resources (see
[Data Catalog roles](https://docs.cloud.google.com/iam/docs/roles-permissions/datacatalog)).

### Console

Navigate to the **Entry group details** page in the
[Data Catalog UI](https://console.cloud.google.com/datacatalog)
then use the IAM panel located on the right side to grant or
revoke permissions.
![](https://docs.cloud.google.com/static/data-catalog/images/iam-console.png)

### gcloud

- Set the IAM policy of an entry group with
  [Google Cloud CLI data-catalog entry-groups set-iam-policy](https://docs.cloud.google.com/sdk/gcloud/reference/data-catalog/entry-groups/set-iam-policy):

  ```
  gcloud data-catalog entry-groups set-iam-policy my_entrygroup \  
      --location=us-central1 \  
      policy file
  ```

  <br />

- Get the IAM policy of an entry group with
  [Google Cloud CLI data-catalog entry-groups get-iam-policy](https://docs.cloud.google.com/sdk/gcloud/reference/data-catalog/entry-groups/get-iam-policy)

  ```
  gcloud data-catalog entry-groups get-iam-policy my_entrygroup \  
      --location=us-central1
  ```

<br />

## Grant entry group roles

### Example 1

A company with different business contexts for its filesets
creates separate `order-files` and `user-files` entry groups:
![The order-files group has storage buckets with cancelled and done order
files whereas the user-files group has a storage bucket with PII files.](https://docs.cloud.google.com/static/data-catalog/images/iam-example1.png) **Figure 1.** An example of how to store order data and user data in different entry groups.

The company grants users the entry group viewer role for `order-files`, meaning
they can only search for entries contained in that entry group. Their search
results don't return entries in `user-files` entry group.

### Example 2

A company grants the entry group viewer role to a user only in the
`project_entry_group` project. The user will only be able to view
entries within that project.

## Search filesets

Users can restrict the scope of search in Data Catalog by using
the `type` facet. `type=entry_group` restricts the search query to
entry groups while `type=fileset` searches only for filesets.
`type` facets can be used in conjunction with other facets, such as `projectid`.

### gcloud

- Search for entry groups in a project:

  ```
  gcloud data-catalog search \  
      --include-project-ids=my-project
      "projectid=my-project type=entry_group"
  ```

  <br />

- Search for all entry groups you can access:

  ```
  gcloud data-catalog search \  
      --include-project-ids=my-project
      "type=entry_group"
  ```

  <br />

- Search for filesets in a project:

  ```
  gcloud data-catalog search \  
      --include-project-ids=my-project
      "type=entry.fileset"
  ```

  <br />

- Search for filesets in a project (simplified syntax):

  ```
  gcloud data-catalog search \  
      --include-project-ids=my-project
      "type=fileset"
  ```

  <br />

<br />

> [!IMPORTANT]
> The [Data Catalog UI](https://console.cloud.google.com/datacatalog) in the Google Cloud console also provides a convenient way to search for entry groups and Cloud Storage filesets.