Skip to content

Commit 439e877

Browse files
committed
Merge branch 'master' into feat/data-loader/cli-add-verbose-logs
2 parents 6b2f321 + c34c508 commit 439e877

File tree

47 files changed

+7072
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7072
-242
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.scalar.db.storage.jdbc;
2+
3+
import com.scalar.db.api.DistributedStorageVirtualTablesIntegrationTestBase;
4+
import java.util.Properties;
5+
6+
public class JdbcDatabaseVirtualTablesIntegrationTest
7+
extends DistributedStorageVirtualTablesIntegrationTestBase {
8+
9+
@Override
10+
protected Properties getProperties(String testName) {
11+
return JdbcEnv.getProperties(testName);
12+
}
13+
}

core/src/main/java/com/scalar/db/api/DistributedStorageAdmin.java

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.scalar.db.api;
22

33
import com.scalar.db.exception.storage.ExecutionException;
4+
import java.util.Collections;
5+
import java.util.Map;
6+
import java.util.Optional;
47

58
/**
69
* An administrative interface for distributed storage implementations. The user can execute
@@ -50,6 +53,203 @@ public interface DistributedStorageAdmin extends Admin, AutoCloseable {
5053
*/
5154
StorageInfo getStorageInfo(String namespace) throws ExecutionException;
5255

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+
53253
/** Closes connections to the storage. */
54254
@Override
55255
void close();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.scalar.db.api;
2+
3+
/**
4+
* Represents information about a virtual table, which is a view created by joining two source
5+
* tables.
6+
*/
7+
public interface VirtualTableInfo {
8+
/**
9+
* Returns the namespace name of the virtual table.
10+
*
11+
* @return the namespace name of the virtual table
12+
*/
13+
String getNamespaceName();
14+
15+
/**
16+
* Returns the table name of the virtual table.
17+
*
18+
* @return the table name of the virtual table
19+
*/
20+
String getTableName();
21+
22+
/**
23+
* Returns the namespace name of the left source table.
24+
*
25+
* @return the namespace name of the left source table
26+
*/
27+
String getLeftSourceNamespaceName();
28+
29+
/**
30+
* Returns the table name of the left source table.
31+
*
32+
* @return the table name of the left source table
33+
*/
34+
String getLeftSourceTableName();
35+
36+
/**
37+
* Returns the namespace name of the right source table.
38+
*
39+
* @return the namespace name of the right source table
40+
*/
41+
String getRightSourceNamespaceName();
42+
43+
/**
44+
* Returns the table name of the right source table.
45+
*
46+
* @return the table name of the right source table
47+
*/
48+
String getRightSourceTableName();
49+
50+
/**
51+
* Returns the join type used to create this virtual table.
52+
*
53+
* @return the join type (INNER or LEFT_OUTER)
54+
*/
55+
VirtualTableJoinType getJoinType();
56+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.scalar.db.api;
2+
3+
/**
4+
* The type of join to perform between two source tables of a virtual table.
5+
*
6+
* <p>This enum defines the types of joins that can be performed when creating a virtual table that
7+
* combines data from two source tables.
8+
*/
9+
public enum VirtualTableJoinType {
10+
/**
11+
* An inner join returns only the rows where there is a match in both source tables based on their
12+
* primary key.
13+
*/
14+
INNER,
15+
16+
/**
17+
* A left outer join returns all rows from the left source table and the matched rows from the
18+
* right source table. If there is no match for a left row, the right-side columns appear as
19+
* {@code NULL}.
20+
*/
21+
LEFT_OUTER
22+
}

0 commit comments

Comments
 (0)