All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.beam.sdk.io.astra.db.transforms.RunCqlQueryFn Maven / Gradle / Ivy

The newest version!
package org.apache.beam.sdk.io.astra.db.transforms;

/*-
 * #%L
 * Beam SDK for Astra
 * --
 * Copyright (C) 2023 DataStax
 * --
 * Licensed under the Apache License, Version 2.0
 * 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.
 * #L%
 */

import org.apache.beam.sdk.io.astra.db.CqlSessionHolder;
import org.apache.beam.sdk.options.ValueProvider;
import org.apache.beam.sdk.transforms.PTransform;
import org.apache.beam.sdk.values.PCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Execute CQL Against Astra.
 *
 * @param 
 *      current bean
 */
public class RunCqlQueryFn extends PTransform, PCollection> {

    /**
     * Logger
     */
    private static final Logger LOG = LoggerFactory.getLogger(CqlSessionHolder.class);

    /**
     * Execute a CQL query
     *
     * @param token
     *      authentication token
     * @param secureConnectBundle
     *      secure connect bundle
     * @param keyspace
     *      target keyspace
     * @param cql
     *      cql query to execute
     */
    public RunCqlQueryFn(String token, byte[] secureConnectBundle, String keyspace, String cql) {
        LOG.info("Executing CQL: {}", cql);
        CqlSessionHolder.getCqlSession(
                ValueProvider.StaticValueProvider.of(token),
                ValueProvider.StaticValueProvider.of(secureConnectBundle),
                ValueProvider.StaticValueProvider.of(keyspace)).execute(cql);
    }

    /**
     * Execute a CQL query
     *
     * @param input
     *      current values in the pipeline
     * @return
     *      same values
     */
    @Override
    public PCollection expand(PCollection input) {
        return input;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy