|
1 | 1 | package com.scalar.db.api; |
2 | 2 |
|
3 | 3 | import com.scalar.db.exception.storage.ExecutionException; |
| 4 | +import java.util.Collections; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.Optional; |
4 | 7 |
|
5 | 8 | /** |
6 | 9 | * An administrative interface for distributed storage implementations. The user can execute |
@@ -50,6 +53,203 @@ public interface DistributedStorageAdmin extends Admin, AutoCloseable { |
50 | 53 | */ |
51 | 54 | StorageInfo getStorageInfo(String namespace) throws ExecutionException; |
52 | 55 |
|
| 56 | + /** |
| 57 | + * Creates a virtual table that exposes a logical join of two source tables on their primary key. |
| 58 | + * This feature is intended for scenarios where related data is stored in separate tables but |
| 59 | + * needs to be accessed or queried as a single logical entity. |
| 60 | + * |
| 61 | + * <p>Semantics: |
| 62 | + * |
| 63 | + * <ul> |
| 64 | + * <li>The join is performed on the primary-key columns of both sources, which must share the |
| 65 | + * same schema (columns, order, and types). |
| 66 | + * <li>Row set depends on {@code joinType}: |
| 67 | + * <ul> |
| 68 | + * <li>{@code INNER}: only keys present in both sources. |
| 69 | + * <li>{@code LEFT_OUTER}: all keys from the left; for left-only keys, the right-side |
| 70 | + * columns appear as {@code NULL}. |
| 71 | + * </ul> |
| 72 | + * <li>Column order: [primary key columns] + [left non-key columns] + [right non-key columns]. |
| 73 | + * <li>No non-key column name conflicts between sources are allowed. |
| 74 | + * <li>Both sources must reside within the atomicity unit of the underlying storage, meaning |
| 75 | + * that the atomicity unit must be at least at the namespace level. |
| 76 | + * <li>Currently, using virtual tables as sources is not supported. |
| 77 | + * </ul> |
| 78 | + * |
| 79 | + * <p>Note: This feature is primarily for internal use. Breaking changes can and will be |
| 80 | + * introduced to it. Users should not depend on it. |
| 81 | + * |
| 82 | + * @param namespace the namespace of the virtual table to create |
| 83 | + * @param table the name of the virtual table to create |
| 84 | + * @param leftSourceNamespace the namespace of the left source table |
| 85 | + * @param leftSourceTable the name of the left source table |
| 86 | + * @param rightSourceNamespace the namespace of the right source table |
| 87 | + * @param rightSourceTable the name of the right source table |
| 88 | + * @param joinType the type of join to perform between the two source tables |
| 89 | + * @param options additional options for creating the virtual table |
| 90 | + * @throws ExecutionException if the operation fails |
| 91 | + * @throws IllegalArgumentException if preconditions are not met (schema mismatch, name conflicts, |
| 92 | + * unsupported atomicity unit, etc.) |
| 93 | + */ |
| 94 | + void createVirtualTable( |
| 95 | + String namespace, |
| 96 | + String table, |
| 97 | + String leftSourceNamespace, |
| 98 | + String leftSourceTable, |
| 99 | + String rightSourceNamespace, |
| 100 | + String rightSourceTable, |
| 101 | + VirtualTableJoinType joinType, |
| 102 | + Map<String, String> options) |
| 103 | + throws ExecutionException; |
| 104 | + |
| 105 | + /** |
| 106 | + * Creates a virtual table that exposes a logical join of two source tables on their primary key. |
| 107 | + * |
| 108 | + * <p>See {@link #createVirtualTable(String, String, String, String, String, String, |
| 109 | + * VirtualTableJoinType, Map)} for semantics. |
| 110 | + * |
| 111 | + * <p>Note: This feature is primarily for internal use. Breaking changes can and will be |
| 112 | + * introduced to it. Users should not depend on it. |
| 113 | + * |
| 114 | + * @param namespace the namespace of the virtual table to create |
| 115 | + * @param table the name of the virtual table to create |
| 116 | + * @param leftSourceNamespace the namespace of the left source table |
| 117 | + * @param leftSourceTable the name of the left source table |
| 118 | + * @param rightSourceNamespace the namespace of the right source table |
| 119 | + * @param rightSourceTable the name of the right source table |
| 120 | + * @param joinType the type of join to perform between the two source tables |
| 121 | + * @param ifNotExists if set to true, the virtual table will be created only if it does not exist |
| 122 | + * already. If set to false, it will throw an exception if it already exists |
| 123 | + * @param options additional options for creating the virtual table |
| 124 | + * @throws ExecutionException if the operation fails |
| 125 | + * @throws IllegalArgumentException if preconditions are not met (schema mismatch, name conflicts, |
| 126 | + * unsupported atomicity unit, etc.) |
| 127 | + */ |
| 128 | + default void createVirtualTable( |
| 129 | + String namespace, |
| 130 | + String table, |
| 131 | + String leftSourceNamespace, |
| 132 | + String leftSourceTable, |
| 133 | + String rightSourceNamespace, |
| 134 | + String rightSourceTable, |
| 135 | + VirtualTableJoinType joinType, |
| 136 | + boolean ifNotExists, |
| 137 | + Map<String, String> options) |
| 138 | + throws ExecutionException { |
| 139 | + if (ifNotExists && tableExists(namespace, table)) { |
| 140 | + return; |
| 141 | + } |
| 142 | + createVirtualTable( |
| 143 | + namespace, |
| 144 | + table, |
| 145 | + leftSourceNamespace, |
| 146 | + leftSourceTable, |
| 147 | + rightSourceNamespace, |
| 148 | + rightSourceTable, |
| 149 | + joinType, |
| 150 | + options); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Creates a virtual table that exposes a logical join of two source tables on their primary key. |
| 155 | + * |
| 156 | + * <p>See {@link #createVirtualTable(String, String, String, String, String, String, |
| 157 | + * VirtualTableJoinType, Map)} for semantics. |
| 158 | + * |
| 159 | + * <p>Note: This feature is primarily for internal use. Breaking changes can and will be |
| 160 | + * introduced to it. Users should not depend on it. |
| 161 | + * |
| 162 | + * @param namespace the namespace of the virtual table to create |
| 163 | + * @param table the name of the virtual table to create |
| 164 | + * @param leftSourceNamespace the namespace of the left source table |
| 165 | + * @param leftSourceTable the name of the left source table |
| 166 | + * @param rightSourceNamespace the namespace of the right source table |
| 167 | + * @param rightSourceTable the name of the right source table |
| 168 | + * @param joinType the type of join to perform between the two source tables |
| 169 | + * @param ifNotExists if set to true, the virtual table will be created only if it does not exist |
| 170 | + * already. If set to false, it will throw an exception if it already exists |
| 171 | + * @throws ExecutionException if the operation fails |
| 172 | + * @throws IllegalArgumentException if preconditions are not met (schema mismatch, name conflicts, |
| 173 | + * unsupported atomicity unit, etc.) |
| 174 | + */ |
| 175 | + default void createVirtualTable( |
| 176 | + String namespace, |
| 177 | + String table, |
| 178 | + String leftSourceNamespace, |
| 179 | + String leftSourceTable, |
| 180 | + String rightSourceNamespace, |
| 181 | + String rightSourceTable, |
| 182 | + VirtualTableJoinType joinType, |
| 183 | + boolean ifNotExists) |
| 184 | + throws ExecutionException { |
| 185 | + createVirtualTable( |
| 186 | + namespace, |
| 187 | + table, |
| 188 | + leftSourceNamespace, |
| 189 | + leftSourceTable, |
| 190 | + rightSourceNamespace, |
| 191 | + rightSourceTable, |
| 192 | + joinType, |
| 193 | + ifNotExists, |
| 194 | + Collections.emptyMap()); |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Creates a virtual table that exposes a logical join of two source tables on their primary key. |
| 199 | + * |
| 200 | + * <p>See {@link #createVirtualTable(String, String, String, String, String, String, |
| 201 | + * VirtualTableJoinType, Map)} for semantics. |
| 202 | + * |
| 203 | + * <p>Note: This feature is primarily for internal use. Breaking changes can and will be |
| 204 | + * introduced to it. Users should not depend on it. |
| 205 | + * |
| 206 | + * @param namespace the namespace of the virtual table to create |
| 207 | + * @param table the name of the virtual table to create |
| 208 | + * @param leftSourceNamespace the namespace of the left source table |
| 209 | + * @param leftSourceTable the name of the left source table |
| 210 | + * @param rightSourceNamespace the namespace of the right source table |
| 211 | + * @param rightSourceTable the name of the right source table |
| 212 | + * @param joinType the type of join to perform between the two source tables |
| 213 | + * @throws ExecutionException if the operation fails |
| 214 | + * @throws IllegalArgumentException if preconditions are not met (schema mismatch, name conflicts, |
| 215 | + * unsupported atomicity unit, etc.) |
| 216 | + */ |
| 217 | + default void createVirtualTable( |
| 218 | + String namespace, |
| 219 | + String table, |
| 220 | + String leftSourceNamespace, |
| 221 | + String leftSourceTable, |
| 222 | + String rightSourceNamespace, |
| 223 | + String rightSourceTable, |
| 224 | + VirtualTableJoinType joinType) |
| 225 | + throws ExecutionException { |
| 226 | + createVirtualTable( |
| 227 | + namespace, |
| 228 | + table, |
| 229 | + leftSourceNamespace, |
| 230 | + leftSourceTable, |
| 231 | + rightSourceNamespace, |
| 232 | + rightSourceTable, |
| 233 | + joinType, |
| 234 | + Collections.emptyMap()); |
| 235 | + } |
| 236 | + |
| 237 | + /** |
| 238 | + * Returns the virtual table information. |
| 239 | + * |
| 240 | + * <p>Note: This feature is primarily for internal use. Breaking changes can and will be |
| 241 | + * introduced to it. Users should not depend on it. |
| 242 | + * |
| 243 | + * @param namespace the namespace |
| 244 | + * @param table the table |
| 245 | + * @return the virtual table information or {@code Optional.empty()} if the table is not a virtual |
| 246 | + * table |
| 247 | + * @throws ExecutionException if the operation fails |
| 248 | + * @throws IllegalArgumentException if the table does not exist |
| 249 | + */ |
| 250 | + Optional<VirtualTableInfo> getVirtualTableInfo(String namespace, String table) |
| 251 | + throws ExecutionException; |
| 252 | + |
53 | 253 | /** Closes connections to the storage. */ |
54 | 254 | @Override |
55 | 255 | void close(); |
|
0 commit comments