Skip to content

Commit e95e72c

Browse files
attempt to salvage really messy logic with simpler conditions
1 parent 4e7db25 commit e95e72c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

R/data.table.R

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,22 +541,26 @@ replace_dot_alias = function(e) {
541541
if (!byjoin || nqbyjoin) {
542542
# Really, `anyDuplicated` in base is AWESOME!
543543
# allow.cartesian shouldn't error if a) not-join, b) 'i' has no duplicates
544-
if (verbose) {last.started.at=proc.time();cat("Constructing irows for '!byjoin || nqbyjoin' ... ");flush.console()}
545-
irows = if (allLen1) f__ else {
544+
if (verbose) {last.started.at=proc.time();catf("Constructing irows for '!byjoin || nqbyjoin' ... ");flush.console()}
545+
if (allLen1) {
546+
irows = f__
547+
} else {
546548
join.many = getOption("datatable.join.many") # #914, default TRUE for backward compatibility
547-
anyDups = if (!join.many && length(f__)==1L && len__==nrow(x)) {
548-
NULL # special case of scalar i match to const duplicated x, not handled by anyDuplicate: data.table(x=c(1L,1L))[data.table(x=1L), on="x"]
549-
} else if (!notjoin && ( # #698. When notjoin=TRUE, ignore allow.cartesian. Rows in answer will never be > nrow(x).
550-
!allow.cartesian ||
551-
!join.many))
552-
as.logical(anyDuplicated(f__, incomparables = c(0L, NA_integer_)))
553-
limit = if (!is.null(anyDups) && anyDups) { # #742. If 'i' has no duplicates, ignore
549+
anyDups = !notjoin &&
550+
(
551+
# #698. When notjoin=TRUE, ignore allow.cartesian. Rows in answer will never be > nrow(x).
552+
(join.many && !allow.cartesian) ||
553+
# special case of scalar i match to const duplicated x, not handled by anyDuplicate: data.table(x=c(1L,1L))[data.table(x=1L), on="x"]
554+
(!join.many && (length(f__) != 1L || len__ != nrow(x)))
555+
) &&
556+
anyDuplicated(f__, incomparables = c(0L, NA_integer_)) > 0L
557+
limit = if (anyDups) { # #742. If 'i' has no duplicates, ignore
554558
if (!join.many) stopf("Joining resulted in many-to-many join. Perform quality check on your data, use mult!='all', or set 'datatable.join.many' option to TRUE to allow rows explosion.")
555-
else if (!allow.cartesian && !notjoin) as.double(nrow(x)+nrow(i))
556-
else internal_error("checking allow.cartesian and join.many, unexpected else branch reached") # nocov
559+
if (allow.cartesian) internal_error("checking allow.cartesian and join.many, unexpected else branch reached") # nocov
560+
as.double(nrow(x)+nrow(i)) # rows in i might not match to x so old max(nrow(x),nrow(i)) wasn't enough. But this limit now only applies when there are duplicates present so the reason now for nrow(x)+nrow(i) is just to nail it down and be bigger than max(nrow(x),nrow(i)).
557561
}
558-
vecseq(f__, len__, limit)
559-
} # rows in i might not match to x so old max(nrow(x),nrow(i)) wasn't enough. But this limit now only applies when there are duplicates present so the reason now for nrow(x)+nrow(i) is just to nail it down and be bigger than max(nrow(x),nrow(i)).
562+
irows = vecseq(f__, len__, limit)
563+
}
560564
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
561565
# Fix for #1092 and #1074
562566
# TODO: implement better version of "any"/"all"/"which" to avoid

0 commit comments

Comments
 (0)