Skip to content

Commit

Permalink
Revert prior optimization commit due to troubleshooting failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Rucknium committed Aug 9, 2022
1 parent 464365b commit d425716
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions construct-edgelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ library(DBI)
data.dir <- ""
# Input data directory here, with trailing "/"

source("https://gist.githubusercontent.com/jeffwong/5925000/raw/bf02ed0dd2963169a91664be02fb18e45c4d1e20/sqlitewritetable.R")
# From https://gist.github.com/jeffwong/5925000
# Modifies RSQLite's sqliteWriteTable function so as to reject duplicates

con <- DBI::dbConnect(RSQLite::SQLite(), paste0(data.dir, "tx-graph-node-indices.db"))

DBI::dbExecute(con, "PRAGMA max_page_count = 4294967292;")
Expand All @@ -21,7 +25,8 @@ DBI::dbExecute(con, "PRAGMA max_page_count = 4294967292;")

DBI::dbExecute(con, "CREATE TABLE nodes (
node TEXT,
node_index INTEGER PRIMARY KEY
node_index INTEGER PRIMARY KEY AUTOINCREMENT,
unique(node)
)")


Expand Down Expand Up @@ -63,31 +68,15 @@ for (file.iter in tx.graph.files) {

new.nodes <- unique(c(tx.graph.chunk$origin, tx.graph.chunk$destination))

nodes.to.insert <- data.frame(node = new.nodes, stringsAsFactors = FALSE)

DBI::dbWriteTable(con, "nodes",
nodes.to.insert, append = TRUE)
nodes.to.insert <- data.frame(node = new.nodes, node_index = NA, stringsAsFactors = FALSE)

mysqliteWriteTable(con, "nodes",
nodes.to.insert, append = TRUE, row.names = FALSE, ignore = TRUE)

cat(nrow(nodes.to.insert), "Nodes written\n")



}

base::date()
DBI::dbExecute(con, "DELETE FROM nodes
WHERE rowid NOT IN (
SELECT MIN(rowid)
FROM nodes
GROUP BY node
)")
base::date()
# 1 hour

# Suggested by https://stackoverflow.com/questions/25884095/how-can-i-delete-duplicates-in-sqlite
# Must do this at the end to make sure did not leave any out
# from the tail end of the last 1000 iters

DBI::dbWriteTable(con, "edgelist_intermediate_1",
data.frame(origin = character(0), destination = character(0),
Expand Down

0 comments on commit d425716

Please sign in to comment.