-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check for index in setkey #3582
Changes from 5 commits
572b64f
c8ddc62
bfefa71
0c64f51
d46358f
057938f
7503aea
3bce910
3b0d3f5
3986117
153ae6c
f2934a2
1809782
a6aa862
9288121
b500253
230e5d1
97d64a5
70b5760
fcb0c5b
bf59b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,12 +86,26 @@ setkeyv <- function(x, cols, verbose=getOption("datatable.verbose"), physical=TR | |
if (!typeof(.xi) %chin% c("integer","logical","character","double")) stop("Column '",i,"' is type '",typeof(.xi),"' which is not supported as a key column type, currently.") | ||
} | ||
if (!is.character(cols) || length(cols)<1L) stop("Internal error. 'cols' should be character at this point in setkey; please report.") # nocov | ||
if (verbose) { | ||
tt = suppressMessages(system.time(o <- forderv(x, cols, sort=TRUE, retGrp=FALSE))) # system.time does a gc, so we don't want this always on, until refcnt is on by default in R | ||
# suppress needed for tests 644 and 645 in verbose mode | ||
cat("forder took", tt["user.self"]+tt["sys.self"], "sec\n") | ||
|
||
# get existing index name if any | ||
found_index <- NULL | ||
if(!is.null(indices(x))){ | ||
found_index <- names(attributes(attributes(x)$index)) | ||
found_index <- gsub("^__","", found_index) | ||
} | ||
|
||
# forder only if index is not present | ||
if(!identical(found_index, cols)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works if there is one index, as the test tests. But there can be multiple indexes (each index is a set of columns). It needs to find if any of the indexes match There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it. |
||
if (verbose) { | ||
tt = suppressMessages(system.time(o <- forderv(x, cols, sort=TRUE, retGrp=FALSE))) # system.time does a gc, so we don't want this always on, until refcnt is on by default in R | ||
# suppress needed for tests 644 and 645 in verbose mode | ||
cat("forder took", tt["user.self"]+tt["sys.self"], "sec\n") | ||
} else { | ||
o <- forderv(x, cols, sort=TRUE, retGrp=FALSE) | ||
} | ||
} else { | ||
o <- forderv(x, cols, sort=TRUE, retGrp=FALSE) | ||
cat("using existing index for", found_index, "\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it. |
||
o <- attr(attributes(x)$index, which=found_index, exact = TRUE) | ||
jangorecki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (!physical) { | ||
if (is.null(attr(x,"index",exact=TRUE))) setattr(x, "index", integer()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer
=
in data.table please. I don't agree with the common and widely marketed advice to use<-
. Single=
is the same as C and many other languages. I sometimes hear, e.g. from Python folk, that R code using<-
looks "old"/"not modern" and I see their point. I've always used=
. I save<-
for use when passing function arguments to do an assign and pass in one go; e.g.write(DT, file=f<-tempfile()); ... do something with f ...
. I'm often swapping between C and R (which I think more people should do too since C is not as hard as some people want you to believe). When doing this, using=
to mean assign and==
to mean equals in two languages consistently (R and C) is nice. And by the way, the people who laugh at R for usingL
postfix to mean integer ... it comes from C (it's the same as C) and it makes a lot of sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for detailed insight. made the change.