|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.doris.connector.api; |
| 19 | + |
| 20 | +import org.apache.doris.connector.api.scan.ConnectorScanPlanProvider; |
| 21 | + |
| 22 | +import java.io.Closeable; |
| 23 | +import java.io.IOException; |
| 24 | +import java.util.Collections; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Set; |
| 27 | + |
| 28 | +/** |
| 29 | + * Main entry point for a connector implementation. |
| 30 | + * |
| 31 | + * <p>A {@code Connector} instance is created once per catalog and provides |
| 32 | + * access to metadata, scan planning, and optional write operations.</p> |
| 33 | + */ |
| 34 | +public interface Connector extends Closeable { |
| 35 | + |
| 36 | + /** Returns the metadata interface for the given session. */ |
| 37 | + ConnectorMetadata getMetadata(ConnectorSession session); |
| 38 | + |
| 39 | + /** Returns the scan plan provider for split generation. */ |
| 40 | + default ConnectorScanPlanProvider getScanPlanProvider() { |
| 41 | + return null; |
| 42 | + } |
| 43 | + |
| 44 | + /** Returns the set of capabilities this connector supports. */ |
| 45 | + default Set<ConnectorCapability> getCapabilities() { |
| 46 | + return Collections.emptySet(); |
| 47 | + } |
| 48 | + |
| 49 | + /** Returns the table-level property descriptors. */ |
| 50 | + default List<ConnectorPropertyMetadata<?>> getTableProperties() { |
| 51 | + return Collections.emptyList(); |
| 52 | + } |
| 53 | + |
| 54 | + /** Returns the session-level property descriptors. */ |
| 55 | + default List<ConnectorPropertyMetadata<?>> getSessionProperties() { |
| 56 | + return Collections.emptyList(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns whether connectivity testing should be enabled by default when |
| 61 | + * the user does not explicitly set the {@code test_connection} property. |
| 62 | + * |
| 63 | + * <p>Connectors that rely on external drivers or remote connectivity |
| 64 | + * (e.g., JDBC) should return {@code true} so that bad configurations |
| 65 | + * are caught at CREATE CATALOG time rather than at first query.</p> |
| 66 | + * |
| 67 | + * @return {@code true} if test_connection defaults to enabled |
| 68 | + */ |
| 69 | + default boolean defaultTestConnection() { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Performs connector-specific validation during CREATE CATALOG. |
| 75 | + * |
| 76 | + * <p>Called before {@link #testConnection(ConnectorSession)}. Connectors |
| 77 | + * may override this to validate driver security, compute checksums, |
| 78 | + * test BE connectivity, or perform any other pre-creation checks.</p> |
| 79 | + * |
| 80 | + * <p>The engine provides infrastructure services through the |
| 81 | + * {@link ConnectorValidationContext}; each connector calls only the |
| 82 | + * services relevant to its validation needs.</p> |
| 83 | + * |
| 84 | + * @param context engine services for validation |
| 85 | + * @throws Exception if validation fails |
| 86 | + */ |
| 87 | + default void preCreateValidation(ConnectorValidationContext context) throws Exception { |
| 88 | + // No-op by default |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Tests connectivity to the underlying data source. |
| 93 | + * |
| 94 | + * <p>Connectors should override this to verify they can reach the |
| 95 | + * metastore, storage, and any other required services.</p> |
| 96 | + * |
| 97 | + * @return the test result; default returns success (no-op test) |
| 98 | + */ |
| 99 | + default ConnectorTestResult testConnection(ConnectorSession session) { |
| 100 | + return ConnectorTestResult.success(); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + default void close() throws IOException { |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Execute a REST passthrough request against the underlying data source. |
| 109 | + * |
| 110 | + * <p>Connectors that expose HTTP endpoints (e.g., Elasticsearch) can |
| 111 | + * override this to proxy REST requests from FE REST APIs.</p> |
| 112 | + * |
| 113 | + * @param path the relative URL path (e.g., "index_name/_search") |
| 114 | + * @param body the request body (may be null for GET-style requests) |
| 115 | + * @return the response body as a JSON string |
| 116 | + * @throws UnsupportedOperationException if the connector doesn't support REST |
| 117 | + */ |
| 118 | + default String executeRestRequest(String path, String body) { |
| 119 | + throw new UnsupportedOperationException("REST passthrough not supported by this connector"); |
| 120 | + } |
| 121 | +} |
0 commit comments