|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.seatunnel.connectors.druid.sink; |
| 20 | + |
| 21 | +import org.apache.seatunnel.api.configuration.ReadonlyConfig; |
| 22 | +import org.apache.seatunnel.api.sink.SinkWriter; |
| 23 | +import org.apache.seatunnel.api.table.catalog.CatalogTable; |
| 24 | +import org.apache.seatunnel.api.table.type.SeaTunnelRow; |
| 25 | +import org.apache.seatunnel.api.table.type.SeaTunnelRowType; |
| 26 | +import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink; |
| 27 | +import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter; |
| 28 | + |
| 29 | +import java.io.IOException; |
| 30 | + |
| 31 | +import static org.apache.seatunnel.connectors.druid.config.DruidConfig.BATCH_SIZE; |
| 32 | +import static org.apache.seatunnel.connectors.druid.config.DruidConfig.COORDINATOR_URL; |
| 33 | +import static org.apache.seatunnel.connectors.druid.config.DruidConfig.DATASOURCE; |
| 34 | + |
| 35 | +public class DruidSink extends AbstractSimpleSink<SeaTunnelRow, Void> { |
| 36 | + |
| 37 | + private ReadonlyConfig config; |
| 38 | + private CatalogTable catalogTable; |
| 39 | + private SeaTunnelRowType seaTunnelRowType; |
| 40 | + |
| 41 | + @Override |
| 42 | + public String getPluginName() { |
| 43 | + return "Druid"; |
| 44 | + } |
| 45 | + |
| 46 | + public DruidSink(ReadonlyConfig config, CatalogTable table) { |
| 47 | + this.config = config; |
| 48 | + this.catalogTable = table; |
| 49 | + this.seaTunnelRowType = catalogTable.getSeaTunnelRowType(); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public AbstractSinkWriter<SeaTunnelRow, Void> createWriter(SinkWriter.Context context) |
| 54 | + throws IOException { |
| 55 | + return new DruidWriter( |
| 56 | + seaTunnelRowType, |
| 57 | + config.get(COORDINATOR_URL), |
| 58 | + config.get(DATASOURCE), |
| 59 | + config.get(BATCH_SIZE)); |
| 60 | + } |
| 61 | +} |
0 commit comments