Skip to content

Commit

Permalink
0003921: Parameter to disable recursive querying of each level in table
Browse files Browse the repository at this point in the history
with self-referencing foreign key
  • Loading branch information
erilong committed Apr 18, 2019
1 parent a533c41 commit 4797eef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Expand Up @@ -165,6 +165,7 @@ private ParameterConstants() {
public final static String INITIAL_LOAD_USE_ESTIMATED_COUNTS = "initial.load.use.estimated.counts";
public final static String INITIAL_LOAD_PURGE_STAGE_IMMEDIATE_THRESHOLD_ROWS = "initial.load.purge.stage.immediate.threshold.rows";
public final static String INITIAL_LOAD_DEFER_CREATE_CONSTRAINTS = "initial.load.defer.create.constraints";
public final static String INITIAL_LOAD_RECURSION_SELF_FK = "initial.load.recursion.self.fk";

public final static String CREATE_TABLE_WITHOUT_DEFAULTS = "create.table.without.defaults";
public final static String CREATE_TABLE_WITHOUT_FOREIGN_KEYS = "create.table.without.foreign.keys";
Expand Down
Expand Up @@ -2797,18 +2797,20 @@ protected CsvData selectNext() {
overrideSelectSql = overrideSelectSql.trim().substring(5);
}

ForeignKey fk = this.sourceTable.getSelfReferencingForeignKey();
if (fk != null) {
Reference[] refs = fk.getReferences();
if (refs.length == 1) {
this.isSelfReferencingFk = true;
this.selfRefParentColumnName = refs[0].getLocalColumnName();
this.selfRefChildColumnName = refs[0].getForeignColumnName();
this.selfRefLevel = 0;
log.info("Ordering rows for table {} using self-referencing foreign key {} -> {}",
this.sourceTable.getName(), this.selfRefParentColumnName, this.selfRefChildColumnName);
} else {
log.warn("Unable to order rows for self-referencing foreign key because it contains multiple columns");
if (parameterService.is(ParameterConstants.INITIAL_LOAD_RECURSION_SELF_FK)) {
ForeignKey fk = this.sourceTable.getSelfReferencingForeignKey();
if (fk != null) {
Reference[] refs = fk.getReferences();
if (refs.length == 1) {
this.isSelfReferencingFk = true;
this.selfRefParentColumnName = refs[0].getLocalColumnName();
this.selfRefChildColumnName = refs[0].getForeignColumnName();
this.selfRefLevel = 0;
log.info("Ordering rows for table {} using self-referencing foreign key {} -> {}",
this.sourceTable.getName(), this.selfRefParentColumnName, this.selfRefChildColumnName);
} else {
log.warn("Unable to order rows for self-referencing foreign key because it contains multiple columns");
}
}
}

Expand Down
Expand Up @@ -733,6 +733,15 @@ initial.load.purge.stage.immediate.threshold.rows=5000
# Type: boolean
initial.load.defer.create.constraints=true

# For tables with self-referencing foreign keys, the initial load will attempt to
# query each level of the rows starting with parent rows, as a way
# to preserve the order of rows.
#
# DatabaseOverridable: true
# Tags: load
# Type: boolean
initial.load.recursion.self.fk=true

# If this is true, registration is opened automatically for nodes requesting it.
#
# DatabaseOverridable: true
Expand Down

0 comments on commit 4797eef

Please sign in to comment.