|
| 1 | +/* Copyright (c) 2022, 2023, Oracle and/or its affiliates. |
| 2 | +
|
| 3 | + This program is free software; you can redistribute it and/or modify |
| 4 | + it under the terms of the GNU General Public License, version 2.0, |
| 5 | + as published by the Free Software Foundation. |
| 6 | +
|
| 7 | + This program is also distributed with certain software (including |
| 8 | + but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | + as designated in a particular file or component or in included license |
| 10 | + documentation. The authors of MySQL hereby grant you an additional |
| 11 | + permission to link the program and your derivative works with the |
| 12 | + separately licensed software that they have included with MySQL. |
| 13 | +
|
| 14 | + This program is distributed in the hope that it will be useful, |
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + GNU General Public License, version 2.0, for more details. |
| 18 | +
|
| 19 | + You should have received a copy of the GNU General Public License |
| 20 | + along with this program; if not, write to the Free Software |
| 21 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 22 | + |
| 23 | +#pragma once |
| 24 | + |
| 25 | +/** |
| 26 | + @file |
| 27 | + This service provides interface for loading data in bulk from CSV files. |
| 28 | +
|
| 29 | +*/ |
| 30 | + |
| 31 | +#include <mysql/components/service.h> |
| 32 | +#include <string> |
| 33 | + |
| 34 | +/* Forward declaration for opaque types. */ |
| 35 | +class THD; |
| 36 | +struct TABLE; |
| 37 | +struct CHARSET_INFO; |
| 38 | + |
| 39 | +using Bulk_loader = void; |
| 40 | + |
| 41 | +/** Bulk loader source. */ |
| 42 | +enum class Bulk_source { |
| 43 | + /** Local file system. */ |
| 44 | + LOCAL, |
| 45 | + /** OCI object store. */ |
| 46 | + OCI, |
| 47 | + /** Amazon S3. */ |
| 48 | + S3 |
| 49 | +}; |
| 50 | + |
| 51 | +/** Bulk loader string attributes. */ |
| 52 | +enum class Bulk_string { |
| 53 | + /** Schema name */ |
| 54 | + SCHEMA_NAME, |
| 55 | + /* Table name */ |
| 56 | + TABLE_NAME, |
| 57 | + /* File prefix URL */ |
| 58 | + FILE_PREFIX, |
| 59 | + /** Column terminator */ |
| 60 | + COLUMN_TERM, |
| 61 | + /** Row terminator */ |
| 62 | + ROW_TERM, |
| 63 | +}; |
| 64 | + |
| 65 | +/** Bulk loader boolean attributes. */ |
| 66 | +enum class Bulk_condition { |
| 67 | + /** The algorithm used is different based on whether the data is in sorted |
| 68 | + primary key order. This option tells whether to expect sorted input. */ |
| 69 | + ORDERED_DATA, |
| 70 | + /** If enclosing is optional. */ |
| 71 | + OPTIONAL_ENCLOSE |
| 72 | +}; |
| 73 | + |
| 74 | +/** Bulk loader size attributes. */ |
| 75 | +enum class Bulk_size { |
| 76 | + /** Number of input files. */ |
| 77 | + COUNT_FILES, |
| 78 | + /** Number of rows to skip. */ |
| 79 | + COUNT_ROW_SKIP, |
| 80 | + /** Number of columns in the table. */ |
| 81 | + COUNT_COLUMNS, |
| 82 | + /** Number of concurrent loaders to use, */ |
| 83 | + CONCURRENCY, |
| 84 | + /** Total memory size to use for LOAD in bytes. */ |
| 85 | + MEMORY |
| 86 | +}; |
| 87 | + |
| 88 | +/** Bulk loader single byte attributes. */ |
| 89 | +enum class Bulk_char { |
| 90 | + /** Escape character. */ |
| 91 | + ESCAPE_CHAR, |
| 92 | + /** Column enclosing character. */ |
| 93 | + ENCLOSE_CHAR |
| 94 | +}; |
| 95 | + |
| 96 | +/** Bulk load driver service. */ |
| 97 | +BEGIN_SERVICE_DEFINITION(bulk_load_driver) |
| 98 | + |
| 99 | +/** |
| 100 | + Create bulk loader. |
| 101 | + @param[in] thd mysql THD |
| 102 | + @param[in] table mysql TABLE object |
| 103 | + @param[in] src bulk loader source |
| 104 | + @param[in] charset source data character set |
| 105 | + @return bulk loader object, opaque type. |
| 106 | +*/ |
| 107 | +DECLARE_METHOD(Bulk_loader *, create_bulk_loader, |
| 108 | + (THD * thd, const TABLE *table, Bulk_source src, |
| 109 | + const CHARSET_INFO *charset)); |
| 110 | +/** |
| 111 | + Set string attribute for loading data. |
| 112 | + @param[in,out] loader bulk loader |
| 113 | + @param[in] type attribute type |
| 114 | + @param[in] value attribute value |
| 115 | +*/ |
| 116 | +DECLARE_METHOD(void, set_string, |
| 117 | + (Bulk_loader * loader, Bulk_string type, std::string value)); |
| 118 | +/** |
| 119 | + Set single byte character attribute for loading data. |
| 120 | + @param[in,out] loader bulk loader |
| 121 | + @param[in] type attribute type |
| 122 | + @param[in] value attribute value |
| 123 | +*/ |
| 124 | +DECLARE_METHOD(void, set_char, |
| 125 | + (Bulk_loader * loader, Bulk_char type, unsigned char value)); |
| 126 | +/** |
| 127 | + Set size attribute for loading data. |
| 128 | + @param[in,out] loader bulk loader |
| 129 | + @param[in] type attribute type |
| 130 | + @param[in] value attribute value |
| 131 | +*/ |
| 132 | +DECLARE_METHOD(void, set_size, |
| 133 | + (Bulk_loader * loader, Bulk_size type, size_t value)); |
| 134 | +/** |
| 135 | + Set boolean condition attribute for loading data. |
| 136 | + @param[in,out] loader bulk loader |
| 137 | + @param[in] type attribute type |
| 138 | + @param[in] value attribute value |
| 139 | +*/ |
| 140 | +DECLARE_METHOD(void, set_condition, |
| 141 | + (Bulk_loader * loader, Bulk_condition type, bool value)); |
| 142 | +/** |
| 143 | + Load data from CSV files. |
| 144 | + @param[in,out] loader bulk loader |
| 145 | + @return true if successful. |
| 146 | +*/ |
| 147 | +DECLARE_METHOD(bool, load, (Bulk_loader * loader, size_t &affected_rows)); |
| 148 | + |
| 149 | +/** |
| 150 | + Drop bulk loader. |
| 151 | + @param[in,out] thd mysql THD |
| 152 | + @param[in,out] loader loader object to drop |
| 153 | +*/ |
| 154 | +DECLARE_METHOD(void, drop_bulk_loader, (THD * thd, Bulk_loader *loader)); |
| 155 | + |
| 156 | +END_SERVICE_DEFINITION(bulk_load_driver) |
0 commit comments