/*
 * 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 org.apache.carbondata.presto;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import io.airlift.bootstrap.LifeCycleManager;
import io.prestosql.plugin.hive.HiveConnector;
import io.prestosql.plugin.hive.HiveTransactionManager;
import io.prestosql.plugin.hive.TransactionalMetadataFactory;
import io.prestosql.spi.connector.ConnectorAccessControl;
import io.prestosql.spi.connector.ConnectorHandleResolver;
import io.prestosql.spi.connector.ConnectorNodePartitioningProvider;
import io.prestosql.spi.connector.ConnectorPageSinkProvider;
import io.prestosql.spi.connector.ConnectorPageSourceProvider;
import io.prestosql.spi.connector.ConnectorSplitManager;
import io.prestosql.spi.connector.SystemTable;
import io.prestosql.spi.eventlistener.EventListener;
import io.prestosql.spi.procedure.Procedure;
import io.prestosql.spi.session.PropertyMetadata;

/**
 * CarbonData connector that extends hive connector for just to set HandleResolver
 */
public class CarbonDataConnector extends HiveConnector {

  public CarbonDataConnector(
      LifeCycleManager lifeCycleManager,
      TransactionalMetadataFactory metadataFactory,
      HiveTransactionManager transactionManager,
      ConnectorSplitManager splitManager,
      ConnectorPageSourceProvider pageSourceProvider,
      ConnectorPageSinkProvider pageSinkProvider,
      ConnectorNodePartitioningProvider nodePartitioningProvider,
      Set<SystemTable> systemTables,
      Set<Procedure> procedures,
      Set<EventListener> eventListeners,
      List<PropertyMetadata<?>> sessionProperties,
      List<PropertyMetadata<?>> schemaProperties,
      List<PropertyMetadata<?>> tableProperties,
      List<PropertyMetadata<?>> analyzeProperties,
      ConnectorAccessControl accessControl,
      ClassLoader classLoader) {
    super(
        lifeCycleManager,
        metadataFactory,
        transactionManager,
        splitManager,
        pageSourceProvider,
        pageSinkProvider,
        nodePartitioningProvider,
        systemTables,
        procedures,
        eventListeners,
        sessionProperties,
        schemaProperties,
        tableProperties,
        analyzeProperties,
        accessControl,
        classLoader);
  }

  @Override
  public Optional<ConnectorHandleResolver> getHandleResolver() {
    // use the CarbonDataHandleResolver to support insert as carbonData operation
    return Optional.of(new CarbonDataHandleResolver());
  }
}
