import asyncio
import os
import sys

# Ensure backend is in path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from common.starrocks_connection import get_db_connection

async def test_like():
    sr = get_db_connection()
    sql = """
    SELECT master_color, 
           LOWER(master_color) LIKE '%xanh lá%' as b_like,
           LOWER(master_color) LIKE '%xanh lá cây%' as b_like_cay
    FROM shared_source.magento_product_dimension_with_text_embedding
    WHERE master_color LIKE '%xanh lá%' OR master_color LIKE '%Xanh lá%'
    LIMIT 10
    """
    rows = await sr.execute_query_async(sql)
    for r in rows:
        print(f"Color: '{r['master_color']}', LIKE '%xanh lá%': {r['b_like']}, LIKE '%xanh lá cây%': {r['b_like_cay']}")
        
    print("-- Testing missing query --")
    sql2 = """
    SELECT COUNT(*) as c
    FROM shared_source.magento_product_dimension_with_text_embedding
    WHERE LOWER(master_color) LIKE '%xanh lá%' OR LOWER(product_color_name) LIKE '%xanh lá%'
    """
    rows2 = await sr.execute_query_async(sql2)
    print(f"Total matched for '%xanh lá%': {rows2[0]['c']}")

if __name__ == "__main__":
    asyncio.run(test_like())
