@@ -74,7 +74,9 @@ class JoinTables { // skipcq: JS-0128
7474 /** @property {DerivedTable } - result table after tables are joined */
7575 this . derivedTable = new DerivedTable ( ) ;
7676
77- ast . JOIN . forEach ( joinTable => this . joinNextTable ( joinTable , ast . FROM . table . toUpperCase ( ) , ast . FROM . as ) ) ;
77+ for ( const joinTable of ast . JOIN ) {
78+ this . joinNextTable ( joinTable , ast . FROM . table . toUpperCase ( ) , ast . FROM . as ) ;
79+ }
7880 }
7981
8082 /**
@@ -105,7 +107,7 @@ class JoinTables { // skipcq: JS-0128
105107 const rightTableName = conditions . table ;
106108 const joinType = conditions . type ;
107109
108- if ( typeof conditions . cond . logic === ' undefined' ) {
110+ if ( conditions . cond . logic === undefined ) {
109111 recIds = this . resolveCondition ( "OR" , [ conditions ] , joinType , rightTableName , leftTableName ) ;
110112 }
111113 else {
@@ -169,7 +171,7 @@ class JoinTables { // skipcq: JS-0128
169171 const result = [ ] ;
170172
171173 for ( let i = 0 ; i < recIds [ 0 ] . length ; i ++ ) {
172- const temp = recIds . map ( rec => typeof rec [ i ] === ' undefined' ? [ ] : rec [ i ] ) ;
174+ const temp = recIds . map ( rec => rec [ i ] === undefined ? [ ] : rec [ i ] ) ;
173175 const row = temp . reduce ( ( accumulator , currentRecords ) => accumulator . filter ( c => currentRecords . includes ( c ) ) , temp [ 0 ] ) ;
174176
175177 if ( row . length > 0 ) {
@@ -191,9 +193,11 @@ class JoinTables { // skipcq: JS-0128
191193 for ( let i = 0 ; i < recIds [ 0 ] . length ; i ++ ) {
192194 let temp = [ ] ;
193195
194- recIds . forEach ( rec => { temp = temp . concat ( rec [ i ] ) } ) ;
196+ for ( const rec of recIds ) {
197+ temp = temp . concat ( rec [ i ] )
198+ } ;
195199
196- if ( typeof temp [ 0 ] !== ' undefined' ) {
200+ if ( temp [ 0 ] !== undefined ) {
197201 result [ i ] = Array . from ( new Set ( temp ) ) ;
198202 }
199203 }
@@ -206,7 +210,7 @@ class JoinTables { // skipcq: JS-0128
206210 * @returns {Boolean }
207211 */
208212 isDerivedTable ( ) {
209- if ( typeof this . derivedTable === ' undefined' ) {
213+ if ( this . derivedTable === undefined ) {
210214 return false ;
211215 }
212216
@@ -441,9 +445,9 @@ class JoinTablesRecordIds {
441445 /** @type {TableField } */
442446 let rightFieldInfo = null ;
443447
444- const left = typeof astJoin . cond === ' undefined' ? astJoin . left : astJoin . cond . left ;
445- const right = typeof astJoin . cond === ' undefined' ? astJoin . right : astJoin . cond . right ;
446- const operator = typeof astJoin . cond === ' undefined' ? astJoin . operator : astJoin . cond . operator ;
448+ const left = astJoin . cond === undefined ? astJoin . left : astJoin . cond . left ;
449+ const right = astJoin . cond === undefined ? astJoin . right : astJoin . cond . right ;
450+ const operator = astJoin . cond === undefined ? astJoin . operator : astJoin . cond . operator ;
447451
448452 leftFieldInfo = this . getTableInfoFromCalculatedField ( left ) ;
449453 rightFieldInfo = this . getTableInfoFromCalculatedField ( right ) ;
@@ -461,7 +465,7 @@ class JoinTablesRecordIds {
461465 }
462466
463467 // joinTable.table is the RIGHT table, so switch if equal to condition left.
464- if ( typeof leftFieldInfo !== ' undefined' && this . rightTableName === leftFieldInfo . originalTable && ! isSelfJoin ) {
468+ if ( leftFieldInfo !== undefined && this . rightTableName === leftFieldInfo . originalTable && ! isSelfJoin ) {
465469 return {
466470 leftSideInfo : rightSideInfo ,
467471 rightSideInfo : leftSideInfo ,
@@ -480,7 +484,7 @@ class JoinTablesRecordIds {
480484 getTableInfoFromCalculatedField ( calcField ) {
481485 let foundTableField = this . tableFields . getFieldInfo ( calcField ) ;
482486
483- if ( typeof foundTableField === ' undefined' && calcField !== '' ) {
487+ if ( foundTableField === undefined && calcField !== '' ) {
484488 // Calculated expression.
485489 foundTableField = this . getReferencedTableInfo ( calcField ) ;
486490 }
@@ -511,7 +515,7 @@ class JoinTablesRecordIds {
511515 // We search the calcField for valid columns - except within quotes.
512516 const quotedConstantsRegEx = / [ " ' ] ( .* ?) [ " ' ] / g;
513517 const opRegEx = / [ + \- / * ( ) ] / g;
514- const results = calcField . replace ( quotedConstantsRegEx , "" ) ;
518+ const results = calcField . replaceAll ( quotedConstantsRegEx , "" ) ;
515519 let parts = results . split ( opRegEx ) ;
516520 parts = parts . map ( a => a . trim ( ) ) . filter ( a => a !== '' ) ;
517521
@@ -531,7 +535,7 @@ class JoinTablesRecordIds {
531535 */
532536 searchColumnsForTable ( calcField , columns ) {
533537 const fieldInfoList = columns . map ( col => this . tableFields . getFieldInfo ( col ) ) ;
534- const validFieldInfo = fieldInfoList . filter ( fld => typeof fld != ' undefined' ) ;
538+ const validFieldInfo = fieldInfoList . filter ( fld => fld != undefined ) ;
535539
536540 if ( validFieldInfo . length > 0 ) {
537541 const foundTableField = { ...validFieldInfo [ 0 ] } ;
@@ -601,17 +605,11 @@ class JoinTablesRecordIds {
601605 let rightRecordIDs = [ ] ;
602606
603607 if ( this . joinFields . operator === '=' ) {
604- // "=" - special case.
605- // Most common case AND far fewer comparisons - especially if right table is large.
608+ // "=" - special case. Most common case AND far fewer comparisons - especially if right table is large.
606609 rightRecordIDs = keyFieldMap . has ( keyMasterJoinField ) ? keyFieldMap . get ( keyMasterJoinField ) : [ ] ;
607610 }
608611 else {
609- // @ts -ignore
610- for ( const [ key , data ] of keyFieldMap ) {
611- if ( conditionFunction ( keyMasterJoinField , key ) ) {
612- rightRecordIDs . unshift ( ...data ) ;
613- }
614- }
612+ rightRecordIDs = this . getJoinRecordIdsForNonEqualCondition ( keyMasterJoinField , keyFieldMap , conditionFunction ) ;
615613 }
616614
617615 // For the current LEFT TABLE record, record the linking RIGHT TABLE records.
@@ -668,4 +666,24 @@ class JoinTablesRecordIds {
668666
669667 return keyFieldMap ;
670668 }
669+
670+ /**
671+ *
672+ * @param {String } keyMasterJoinField
673+ * @param {Map<String, Number[]> } keyFieldMap
674+ * @param {Function } conditionFunction
675+ * @returns {Number[] }
676+ */
677+ getJoinRecordIdsForNonEqualCondition ( keyMasterJoinField , keyFieldMap , conditionFunction ) {
678+ const recordIDs = [ ] ;
679+
680+ // @ts -ignore
681+ for ( const [ key , data ] of keyFieldMap ) {
682+ if ( conditionFunction ( keyMasterJoinField , key ) ) {
683+ recordIDs . unshift ( ...data ) ;
684+ }
685+ }
686+
687+ return recordIDs ;
688+ }
671689}
0 commit comments