/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.kyligence.kap.secondstorage.util;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SecondStorageSqlUtilsTest {

    @Test
    public void test() {
        String createTableSql = "CREATE TABLE ke_metadata_p_test_01\n"
                + ".cfb0ae66_7d59_4eb7_bb0b_bd0ce57069ed_20000000001_temp\n"
                + "(`c0` Nullable(Int64),`c1` Nullable(Int32),`c7` Nullable(Int32),`c10` Date,`c15` Nullable(Int64),`c16` Nullable(Int32)) \n"
                + "ENGINE = MergeTree() \n"
                + "PARTITION BY `c10` ORDER BY tuple()";
        String createTableSqlExpected = "CREATE TABLE IF NOT EXISTS ke_metadata_p_test_01\n"
                + ".cfb0ae66_7d59_4eb7_bb0b_bd0ce57069ed_20000000001_temp\n"
                + "(`c0` Nullable(Int64),`c1` Nullable(Int32),`c7` Nullable(Int32),`c10` Date,`c15` Nullable(Int64),`c16` Nullable(Int32)) \n"
                + "ENGINE = MergeTree() \n"
                + "PARTITION BY `c10` ORDER BY tuple()";

        String createTableSql2 = SecondStorageSqlUtils.addIfNotExists(createTableSql, "TABLE");
        Assertions.assertEquals(createTableSql2, createTableSqlExpected);

        String createDatabaseSql = "CREATE DATABASE ke_metadata_p_test_01\n"
                + "ENGINE = Atomic";
        String createDatabaseSqlExcepted = "CREATE DATABASE IF NOT EXISTS ke_metadata_p_test_01\n"
                + "ENGINE = Atomic";

        String createDatabaseSql2 = SecondStorageSqlUtils.addIfNotExists(createDatabaseSql, "DATABASE");
        Assertions.assertEquals(createDatabaseSql2, createDatabaseSqlExcepted);
    }
}
