# Test 6: Upload Commands and App Creation

## Step 1: Upload Files to Stage

```sql
-- Upload the enhanced test file
PUT file:///Users/mach071/Documents/collab/mymac80/spark/hello_world_tests/test_6_import_with_logging.py @spark_streamlit_stage;

-- Upload the math_utils module (from archive)
PUT file:///Users/mach071/Documents/collab/mymac80/spark/hello_world_tests/archive/math_utils.py @spark_streamlit_stage;
```

## Step 2: Verify File Upload

```sql
-- List files in the stage
LIST @spark_streamlit_stage;
```

## Step 3: Create Event Table (if not already created)

```sql
-- Run the event table setup from container_runtime_setup.sql
-- Execute STEP 5A commands
```

## Step 4: Create Streamlit App

```sql
CREATE STREAMLIT FANSIFTER_APP_REPORTING.DEV_MMACHADO.spark_test_6_import_logging
    ROOT_LOCATION = '@FANSIFTER_APP_REPORTING.DEV_MMACHADO.spark_streamlit_stage'
    MAIN_FILE = 'test_6_import_with_logging.py'
    QUERY_WAREHOUSE = DEV_OWS_WH
    COMPUTE_POOL = spark_streamlit_pool
    EXTERNAL_ACCESS_INTEGRATIONS = (spark_external_access)
    COMMENT = 'Test 6: Enhanced import diagnostics with comprehensive logging and tracing';
```

## Step 5: Launch and Test

1. **Run the Streamlit app** from Snowsight
2. **Observe the detailed diagnostics** in the app interface
3. **Check logs and traces** using the provided SQL queries

## Step 6: Analyze Results

```sql
-- View all logs from the import test (for log records)
SELECT 
    timestamp,
    record_type,
    record:severity::STRING as severity,
    record:body::STRING as body,
    scope:name::STRING as logger_name
FROM spark_event_table
WHERE record_type = 'LOG'
  AND scope:name::STRING = 'import_diagnostics'
ORDER BY timestamp DESC;

-- View trace events (for event records)
SELECT 
    timestamp,
    record_type,
    record:name::STRING as event_name,
    record_attributes
FROM spark_event_table  
WHERE record_type = 'SPAN_EVENT'
  AND record:name::STRING IN ('import_success', 'import_failure', 'import_error', 'system_info_collected')
ORDER BY timestamp DESC;

-- Error analysis for span events
SELECT 
    record:name::STRING as event_name,
    record_attributes:import_type::STRING as import_type,
    record_attributes:error::STRING as error_message,
    COUNT(*) as frequency
FROM spark_event_table
WHERE record_type = 'SPAN_EVENT'
  AND record:name::STRING IN ('import_failure', 'import_error')
GROUP BY record:name, record_attributes:import_type, record_attributes:error;

-- Alternative: View all event table records to understand structure
SELECT 
    timestamp,
    record_type,
    record,
    record_attributes,
    scope
FROM spark_event_table
ORDER BY timestamp DESC
LIMIT 20;
```

## Expected Insights

This enhanced test should provide:
- **Detailed error traces** showing exactly why imports fail
- **File system insights** into how Container Runtime stores modules  
- **Performance timing** for different import methods
- **System environment details** that affect module loading
- **Comprehensive logs** for future troubleshooting reference

The results will either:
1. **Confirm Phase 0 findings** that imports don't work (with detailed why)
2. **Reveal specific conditions** where imports might work
3. **Provide debugging patterns** for similar Container Runtime issues