# Table Exists Example

This example demonstrates how to use the `TableExists` function in the Delta Lake Go SDK to check if a Delta table exists at a given path before performing operations on it.

## Features Demonstrated

1. **Basic existence check** - Check if a table exists at a given path
2. **Non-existent table handling** - Verify that non-existent tables return false
3. **Storage options support** - Check table existence with custom storage options
4. **Error handling** - Handle invalid paths and error cases
5. **Integration with table operations** - Use existence check before opening tables

## Usage

To run this example:

```bash
cd examples/table_exists
go run table_exists.go
```

To build and run:

```bash
cd examples/table_exists
go build
./table_exists
```

## Code Overview

The example shows several use cases:

### 1. Check Non-Existent Table
```go
exists, err := deltalake.TableExists(tablePath, nil)
// Returns: false, nil
```

### 2. Check After Table Creation
```go
// Create table first
table, err := deltalake.CreateDeltaLakeTable(options)
defer table.Close()

// Then check existence
exists, err := deltalake.TableExists(tablePath, nil)
// Returns: true, nil
```

### 3. Check with Storage Options
```go
storageOptions := map[string]string{
    "AWS_REGION": "us-west-2",
    "AWS_S3_ALLOW_UNSAFE_RENAME": "true",
}
exists, err := deltalake.TableExists(tablePath, storageOptions)
```

### 4. Error Handling
```go
exists, err := deltalake.TableExists("", nil)
// Returns: false, error ("table path cannot be empty")
```

### 5. Integration with OpenDeltaLakeTable
```go
// Check if table exists before opening
exists, err := deltalake.TableExists(tablePath, nil)
if err != nil {
    return err
}

if exists {
    table, err := deltalake.OpenDeltaLakeTable(tablePath, nil)
    // ... use table
}
```

## Benefits

Using `TableExists` helps you:

- Avoid errors when trying to open non-existent tables
- Implement conditional logic based on table existence
- Provide better error messages to users
- Optimize performance by avoiding unnecessary open attempts

## Implementation Details

The `TableExists` function uses the underlying Delta Lake Rust library's `DeltaTableBuilder` and `verify_deltatable_existence()` method to efficiently check table existence without fully loading the table metadata.