import pandas as pd
import pandas.testing as tm
import pytest
from pytest import param

import ibis
import ibis.common.exceptions as com
from ibis.backends.pyspark.compiler import _can_be_replaced_by_column_name


def test_basic(client):
    table = client.table('basic_table')
    result = table.compile().toPandas()
    expected = pd.DataFrame({'id': range(0, 10), 'str_col': 'value'})

    tm.assert_frame_equal(result, expected)


def test_projection(client):
    table = client.table('basic_table')
    result1 = table.mutate(v=table['id']).compile().toPandas()

    expected1 = pd.DataFrame(
        {'id': range(0, 10), 'str_col': 'value', 'v': range(0, 10)}
    )

    result2 = (
        table.mutate(v=table['id'])
        .mutate(v2=table['id'])
        .mutate(id=table['id'] * 2)
        .compile()
        .toPandas()
    )

    expected2 = pd.DataFrame(
        {
            'id': range(0, 20, 2),
            'str_col': 'value',
            'v': range(0, 10),
            'v2': range(0, 10),
        }