@@ -107,11 +107,14 @@ static void validatePrimaryKey(const std::string& pkColName,
107
107
}
108
108
}
109
109
110
- BoundCreateTableInfo Binder::bindCreateTableInfo (const parser::CreateTableInfo* info) {
111
- switch (info-> tableType ) {
110
+ BoundCreateTableInfo Binder::bindCreateTableInfo (const parser::CreateTableInfo& info) {
111
+ switch (info. tableType ) {
112
112
case TableType::NODE: {
113
113
return bindCreateNodeTableInfo (info);
114
114
}
115
+ case TableType::EXTERNAL_NODE: {
116
+ return bindCreateExternalNodeTableInfo (info);
117
+ }
115
118
case TableType::REL: {
116
119
return bindCreateRelTableInfo (info);
117
120
}
@@ -127,24 +130,57 @@ BoundCreateTableInfo Binder::bindCreateTableInfo(const parser::CreateTableInfo*
127
130
}
128
131
}
129
132
130
- BoundCreateTableInfo Binder::bindCreateNodeTableInfo (const CreateTableInfo* info) {
131
- auto propertyDefinitions = bindPropertyDefinitions (info-> propertyDefinitions , info-> tableName );
132
- auto & extraInfo = info-> extraInfo ->constCast <ExtraCreateNodeTableInfo>();
133
+ BoundCreateTableInfo Binder::bindCreateNodeTableInfo (const CreateTableInfo& info) {
134
+ auto propertyDefinitions = bindPropertyDefinitions (info. propertyDefinitions , info. tableName );
135
+ auto & extraInfo = info. extraInfo ->constCast <ExtraCreateNodeTableInfo>();
133
136
validatePrimaryKey (extraInfo.pKName , propertyDefinitions);
134
137
auto boundExtraInfo = std::make_unique<BoundExtraCreateNodeTableInfo>(extraInfo.pKName ,
135
138
std::move (propertyDefinitions));
136
- return BoundCreateTableInfo (TableType::NODE, info-> tableName , info-> onConflict ,
139
+ return BoundCreateTableInfo (TableType::NODE, info. tableName , info. onConflict ,
137
140
std::move (boundExtraInfo));
138
141
}
139
142
140
- BoundCreateTableInfo Binder::bindCreateRelTableInfo (const CreateTableInfo* info) {
143
+ static PropertyDefinition getDefinition (const std::vector<PropertyDefinition>& definitions, const std::string& name) {
144
+ for (auto & definition : definitions) {
145
+ if (definition.getName () == name) {
146
+ return definition.copy ();
147
+ }
148
+ }
149
+ // LCOV_EXCL_START
150
+ throw BinderException (stringFormat (" Cannot find property with name {}." , name));
151
+ // LCOV_EXCL_STOP
152
+ }
153
+
154
+ static std::string getPhysicalTableName (std::string name) {
155
+ return " _" + name;
156
+ }
157
+
158
+ BoundCreateTableInfo Binder::bindCreateExternalNodeTableInfo (const CreateTableInfo& info) {
159
+ auto & extraInfo = info.extraInfo ->constCast <ExtraCreateExternalNodeTableInfo>();
160
+ auto entry = bindExternalTableEntry (extraInfo.dbName , extraInfo.tableName );
161
+ auto & propertyDefinitions = entry->getProperties ();
162
+ // Bind physical create node table info
163
+ auto pkDefinition = getDefinition (propertyDefinitions, extraInfo.pkName );
164
+ std::vector<PropertyDefinition> physicalPropertyDefinitions;
165
+ physicalPropertyDefinitions.push_back (pkDefinition.copy ());
166
+ auto boundPhysicalExtraInfo = std::make_unique<BoundExtraCreateNodeTableInfo>(extraInfo.pkName , std::move (physicalPropertyDefinitions));
167
+ auto boundPhysicalCreateInfo = BoundCreateTableInfo (TableType::NODE,
168
+ getPhysicalTableName (info.tableName ), ConflictAction::ON_CONFLICT_THROW,
169
+ std::move (boundPhysicalExtraInfo));
170
+ // Bind create node table reference info
171
+ auto boundExtraInfo = std::make_unique<BoundExtraCreateExternalNodeTableInfo>(extraInfo.pkName ,
172
+ extraInfo.dbName , extraInfo.tableName , std::move (boundPhysicalCreateInfo), copyVector (propertyDefinitions));
173
+ return BoundCreateTableInfo (TableType::EXTERNAL_NODE, info.tableName , info.onConflict , std::move (boundExtraInfo));
174
+ }
175
+
176
+ BoundCreateTableInfo Binder::bindCreateRelTableInfo (const CreateTableInfo& info) {
141
177
std::vector<PropertyDefinition> propertyDefinitions;
142
178
propertyDefinitions.emplace_back (
143
179
ColumnDefinition (InternalKeyword::ID, LogicalType::INTERNAL_ID ()));
144
- for (auto & definition : bindPropertyDefinitions (info-> propertyDefinitions , info-> tableName )) {
180
+ for (auto & definition : bindPropertyDefinitions (info. propertyDefinitions , info. tableName )) {
145
181
propertyDefinitions.push_back (definition.copy ());
146
182
}
147
- auto & extraInfo = info-> extraInfo ->constCast <ExtraCreateRelTableInfo>();
183
+ auto & extraInfo = info. extraInfo ->constCast <ExtraCreateRelTableInfo>();
148
184
auto srcMultiplicity = RelMultiplicityUtils::getFwd (extraInfo.relMultiplicity );
149
185
auto dstMultiplicity = RelMultiplicityUtils::getBwd (extraInfo.relMultiplicity );
150
186
auto srcTableID = bindTableID (extraInfo.srcTableName );
@@ -153,7 +189,7 @@ BoundCreateTableInfo Binder::bindCreateRelTableInfo(const CreateTableInfo* info)
153
189
validateTableType (dstTableID, TableType::NODE);
154
190
auto boundExtraInfo = std::make_unique<BoundExtraCreateRelTableInfo>(srcMultiplicity,
155
191
dstMultiplicity, srcTableID, dstTableID, std::move (propertyDefinitions));
156
- return BoundCreateTableInfo (TableType::REL, info-> tableName , info-> onConflict ,
192
+ return BoundCreateTableInfo (TableType::REL, info. tableName , info. onConflict ,
157
193
std::move (boundExtraInfo));
158
194
}
159
195
@@ -162,29 +198,29 @@ static std::string getRelGroupTableName(const std::string& relGroupName,
162
198
return relGroupName + " _" + srcTableName + " _" + dstTableName;
163
199
}
164
200
165
- BoundCreateTableInfo Binder::bindCreateRelTableGroupInfo (const CreateTableInfo* info) {
166
- auto relGroupName = info-> tableName ;
167
- auto & extraInfo = info-> extraInfo ->constCast <ExtraCreateRelTableGroupInfo>();
201
+ BoundCreateTableInfo Binder::bindCreateRelTableGroupInfo (const CreateTableInfo& info) {
202
+ auto relGroupName = info. tableName ;
203
+ auto & extraInfo = info. extraInfo ->constCast <ExtraCreateRelTableGroupInfo>();
168
204
auto relMultiplicity = extraInfo.relMultiplicity ;
169
205
std::vector<BoundCreateTableInfo> boundCreateRelTableInfos;
170
- auto relCreateInfo = std::make_unique< CreateTableInfo> (TableType::REL, " " , info-> onConflict );
171
- relCreateInfo-> propertyDefinitions = copyVector (info-> propertyDefinitions );
206
+ auto relCreateInfo = CreateTableInfo (TableType::REL, " " , info. onConflict );
207
+ relCreateInfo. propertyDefinitions = copyVector (info. propertyDefinitions );
172
208
for (auto & [srcTableName, dstTableName] : extraInfo.srcDstTablePairs ) {
173
- relCreateInfo-> tableName = getRelGroupTableName (relGroupName, srcTableName, dstTableName);
174
- relCreateInfo-> extraInfo =
209
+ relCreateInfo. tableName = getRelGroupTableName (relGroupName, srcTableName, dstTableName);
210
+ relCreateInfo. extraInfo =
175
211
std::make_unique<ExtraCreateRelTableInfo>(relMultiplicity, srcTableName, dstTableName);
176
- boundCreateRelTableInfos.push_back (bindCreateRelTableInfo (relCreateInfo. get () ));
212
+ boundCreateRelTableInfos.push_back (bindCreateRelTableInfo (relCreateInfo));
177
213
}
178
214
auto boundExtraInfo =
179
215
std::make_unique<BoundExtraCreateRelTableGroupInfo>(std::move (boundCreateRelTableInfos));
180
- return BoundCreateTableInfo (TableType::REL_GROUP, info-> tableName , info-> onConflict ,
216
+ return BoundCreateTableInfo (TableType::REL_GROUP, info. tableName , info. onConflict ,
181
217
std::move (boundExtraInfo));
182
218
}
183
219
184
220
std::unique_ptr<BoundStatement> Binder::bindCreateTable (const Statement& statement) {
185
221
auto createTable = statement.constPtrCast <CreateTable>();
186
- auto tableName = createTable->getInfo ()-> tableName ;
187
- switch (createTable->getInfo ()-> onConflict ) {
222
+ auto tableName = createTable->getInfo (). tableName ;
223
+ switch (createTable->getInfo (). onConflict ) {
188
224
case common::ConflictAction::ON_CONFLICT_THROW: {
189
225
if (clientContext->getCatalog ()->containsTable (clientContext->getTx (), tableName)) {
190
226
throw BinderException (tableName + " already exists in catalog." );
0 commit comments