def DetectType(ref, args, request):
    """Detect Entry type.

  Args:
    ref: The entry resource reference.
    args: The parsed args namespace.
    request: The update entry request.

  Returns:
    Request with proper type
  """

    del ref
    client = entries_v1.EntriesClient()
    messages = client.messages

    if args.IsSpecified('kafka_cluster_bootstrap_servers'):
        arg_utils.SetFieldInMessage(
            request, 'googleCloudDatacatalogV1Entry.type',
            messages.GoogleCloudDatacatalogV1Entry.TypeValueValuesEnum.CLUSTER)
    if args.IsSpecified('kafka_topic'):
        arg_utils.SetFieldInMessage(
            request, 'googleCloudDatacatalogV1Entry.type', messages.
            GoogleCloudDatacatalogV1Entry.TypeValueValuesEnum.DATA_STREAM)
    return request
def MergeGcsFilePatterns(ref, args, request):
    """Merges user-provided GCS file patterns with existing patterns.

  Args:
    ref: The entry resource reference.
    args: The parsed args namespace.
    request: The update entry request.

  Returns:
    Request with merged GCS file pattern.
  """
    if not _IsChangeFilePatternSpecified(args):
        return request

    del ref
    entry_ref = args.CONCEPTS.entry.Parse()

    file_patterns = entries_v1.EntriesClient().Get(
        entry_ref).gcsFilesetSpec.filePatterns or []
    if args.IsSpecified('clear_file_patterns'):
        file_patterns = []
    if args.IsSpecified('remove_file_patterns'):
        to_remove = set(args.remove_file_patterns)
        file_patterns = [b for b in file_patterns if b not in to_remove]
    if args.IsSpecified('add_file_patterns'):
        file_patterns += args.add_file_patterns

    arg_utils.SetFieldInMessage(
        request, 'googleCloudDatacatalogV1Entry.gcsFilesetSpec.filePatterns',
        file_patterns)

    request.updateMask += ',gcsFilesetSpec.filePatterns'
    return request
def ParsePhysicalSchema(ref, args, request):
    """Parses physical schema from file after obtaining information about its type.

  Args:
    ref: The entry resource reference.
    args: The parsed args namespace.
    request: The update entry request.

  Returns:
    Request with merged GCS file pattern.

  Raises:
    InvalidPhysicalSchemaError: if physical schema type is unknown
  """
    if not args.IsSpecified('physical_schema_type'):
        return request

    del ref
    client = entries_v1.EntriesClient()
    messages = client.messages

    if args.IsSpecified('physical_schema_file'):
        schema_abs_path = path.expanduser(args.physical_schema_file)
        schema_text = files.ReadFileContents(schema_abs_path)
    else:
        schema_text = ''

    schema_type = args.physical_schema_type

    if schema_type == 'avro':
        schema = messages.GoogleCloudDatacatalogV1PhysicalSchemaAvroSchema()
        schema.text = schema_text
    elif schema_type == 'thrift':
        schema = messages.GoogleCloudDatacatalogV1PhysicalSchemaThriftSchema()
        schema.text = schema_text
    elif schema_type == 'protobuf':
        schema = messages.GoogleCloudDatacatalogV1PhysicalSchemaProtobufSchema(
        )
        schema.text = schema_text
    elif schema_type == 'parquet':
        schema = messages.GoogleCloudDatacatalogV1PhysicalSchemaParquetSchema()
    elif schema_type == 'orc':
        schema = messages.GoogleCloudDatacatalogV1PhysicalSchemaOrcSchema()
    else:
        raise InvalidPhysicalSchemaError(
            'Unknown physical schema type. Must be one of: avro, thrift, protobuf,'
            'parquet, orc')

    arg_utils.SetFieldInMessage(
        request,
        'googleCloudDatacatalogV1Entry.schema.physicalSchema.' + schema_type,
        schema)

    return request
def LookupAndParseEntry(ref, args, request):
    """Parses the entry into the request, performing a lookup first if necessary.

  Args:
    ref: None.
    args: The parsed args namespace.
    request: The update entry request.

  Returns:
    Request containing the parsed entry.
  Raises:
    UnderSpecifiedEntryError: if ENTRY was only partially specified.
    RequiredMutexGroupError: if both or neither ENTRY, --lookup-entry specified.
  """
    del ref
    entry_ref = args.CONCEPTS.entry.Parse()

    # Parse() will raise an error if the entry flags are specified without the
    # anchor, so we don't need to handle that case. However no error is returned
    # if a positional is specified but parsing fails, so we check for that here.
    if args.IsSpecified('entry') and not entry_ref:
        raise UnderSpecifiedEntryError(
            'Argument [ENTRY : --entry-group=ENTRY_GROUP --location=LOCATION] was '
            'not fully specified.')

    if ((entry_ref and args.IsSpecified('lookup_entry'))
            or (not entry_ref and not args.IsSpecified('lookup_entry'))):
        raise concept_exceptions.RequiredMutexGroupError(
            'entry',
            '([ENTRY : --entry-group=ENTRY_GROUP --location=LOCATION] '
            '| --lookup-entry)')

    if entry_ref:
        request.name = entry_ref.RelativeName()
    else:
        client = entries_v1.EntriesClient()
        request.name = client.Lookup(args.lookup_entry).name
    return request