{
  "id": 23362,
  "title": "Using a SQL database",
  "url": "/competitions/bosch-production-line-performance/discussion/23362",
  "author_name": "",
  "post_date": "2016-09-04T22:21:23.233Z",
  "votes": 3,
  "comment_count": 12,
  "views": 1728,
  "content": "<p>I know all the cool kids are going to the Hadoop cluster, but this data is THAT big =)</p>\n\n<p>Anyway it is big enough that I cannot load into memory--my first thought was putting it in a personal database--has anyone else thought along that line?  I got my start in traditional SQL dbs so it seemed natural to just load the data up and even manipulate it using that method to take advantage of hard drive space, rather than memory.</p>\n\n<p>Anyone else approaching it that way?  I went postgresql and got the numeric data loaded pretty quick (a few minutes).  </p>",
  "messages": [
    {
      "id": "134063",
      "postDate": "09/04/2016 22:21:23",
      "content": "<p>I know all the cool kids are going to the Hadoop cluster, but this data is THAT big =)</p>\n\n<p>Anyway it is big enough that I cannot load into memory--my first thought was putting it in a personal database--has anyone else thought along that line?  I got my start in traditional SQL dbs so it seemed natural to just load the data up and even manipulate it using that method to take advantage of hard drive space, rather than memory.</p>\n\n<p>Anyone else approaching it that way?  I went postgresql and got the numeric data loaded pretty quick (a few minutes).  </p>",
      "rawMarkdown": "I know all the cool kids are going to the Hadoop cluster, but this data is THAT big =)\r\n\r\nAnyway it is big enough that I cannot load into memory--my first thought was putting it in a personal database--has anyone else thought along that line?  I got my start in traditional SQL dbs so it seemed natural to just load the data up and even manipulate it using that method to take advantage of hard drive space, rather than memory.\r\n\r\n\r\nAnyone else approaching it that way?  I went postgresql and got the numeric data loaded pretty quick (a few minutes).",
      "votes": null
    },
    {
      "id": "135805",
      "postDate": "09/17/2016 05:05:00",
      "content": "<p>I'm experimenting with that route as well.  </p>",
      "rawMarkdown": "I'm experimenting with that route as well.",
      "votes": null
    },
    {
      "id": "135844",
      "postDate": "09/17/2016 16:16:38",
      "content": "<p>Since you can't use SQL to build models and make any kind of predictive analysis anyway, why not using <em>data.table</em> in R? It is capable of handling way bigger datasets. And in some sense it behaves similar to SQL (you can also make joins, for example).\nIt took me 1 minute on a laptop to read &quot;test_numeric.csv&quot;. </p>\n\n<pre><code>require(data.table)\nrequire(bit64)\n\ntest = fread(&quot;test_numeric.csv&quot;)\n&gt; test = fread(&quot;test_numeric.csv&quot;)\nRead 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:01:08\n(of 969) columns from 1.991 GB file in 00:01:08\n\n&gt; dim(test)\n[1] 1183748     969\n</code></pre>",
      "rawMarkdown": "Since you can't use SQL to build models and make any kind of predictive analysis anyway, why not using *data.table* in R? It is capable of handling way bigger datasets. And in some sense it behaves similar to SQL (you can also make joins, for example).\r\nIt took me 1 minute on a laptop to read \"test_numeric.csv\". \r\n\r\n    require(data.table)\r\n    require(bit64)\r\n\r\n    test = fread(\"test_numeric.csv\")\r\n    > test = fread(\"test_numeric.csv\")\r\n    Read 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:01:08\r\n    (of 969) columns from 1.991 GB file in 00:01:08\r\n\r\n    > dim(test)\r\n    [1] 1183748     969",
      "votes": null
    },
    {
      "id": "135943",
      "postDate": "09/18/2016 17:13:40",
      "content": "<p>Memory limits.  I only have 8GB of memory.</p>",
      "rawMarkdown": "Memory limits.  I only have 8GB of memory.",
      "votes": null
    },
    {
      "id": "135944",
      "postDate": "09/18/2016 17:22:10",
      "content": "<p>Hi, </p>\n\n<p>I have used the same.I am getting the below error. </p>\n\n<p>test = fread(&quot;test_numeric.csv&quot;)</p>\n\n<p>Read 0.0% of 1183748 rows</p>\n\n<p>Error: cannot allocate vector of size 9.0 Mb</p>\n\n<p>In addition: There were 20 warnings (use warnings() to see them)</p>\n\n<p>Can someone help me to resolve this?</p>\n\n<p>Thank you.</p>",
      "rawMarkdown": "Hi, \r\n\r\nI have used the same.I am getting the below error. \r\n\r\ntest = fread(\"test_numeric.csv\")\r\n\r\nRead 0.0% of 1183748 rows\r\n\r\nError: cannot allocate vector of size 9.0 Mb\r\n\r\nIn addition: There were 20 warnings (use warnings() to see them)\r\n\r\n\r\n\r\nCan someone help me to resolve this?\r\n\r\n\r\nThank you.",
      "votes": null
    },
    {
      "id": "135947",
      "postDate": "09/18/2016 17:45:41",
      "content": "<p>Now,I got it.I changes to :</p>\n\n<p>memory.limit(size=10000)</p>\n\n<p>Read 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:05:10</p>",
      "rawMarkdown": "Now,I got it.I changes to :\r\n\r\nmemory.limit(size=10000)\r\n\r\nRead 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:05:10",
      "votes": null
    },
    {
      "id": "136175",
      "postDate": "09/20/2016 12:19:03",
      "content": "<p>Here is the script I used to load the data into SQLight. In case you don't have enough RAM to execute it, you could play with nrows and skip in fread() to process data in chunks. For this to work, you might need to write an additional INSERT-statement and execute it with dbSendQuery. Better/faster approaches are welcome :)</p>\n\n<pre><code># install/load packages\nif (!require(&quot;pacman&quot;)) install.packages(&quot;pacman&quot;)\npacman::p_load(data.table, RSQLite)\n\n# Set path and database name\npath &lt;- &quot;./data&quot;\nsetwd(path)\nsqlite &lt;- dbDriver(&quot;SQLite&quot;)\ncon &lt;- dbConnect(sqlite, &quot;20160920_kgl_Bosch.sqlite3&quot;)\n\n# Loop through all csv files in path and write them to SQLight\nfor (file in list.files(pattern = &quot;*.csv&quot;)){\n  print(Sys.time())\n  print(file)\n  data &lt;- fread(file)\n  tbl_name &lt;- gsub(&quot;.csv&quot;,&quot;&quot;, file)\n\n  if (dbExistsTable(con, tbl_name) == FALSE){\n    dbWriteTable(con, tbl_name, data)\n  }\n\n  # Create an index on the Id-column to improve performance on later queries\n  dbSendQuery(con, paste0(&quot;CREATE UNIQUE INDEX idx_&quot;, tbl_name, &quot; ON &quot;, tbl_name, &quot;(Id)&quot;))\n  rm(data)\n  gc()\n}\n</code></pre>",
      "rawMarkdown": "Here is the script I used to load the data into SQLight. In case you don't have enough RAM to execute it, you could play with nrows and skip in fread() to process data in chunks. For this to work, you might need to write an additional INSERT-statement and execute it with dbSendQuery. Better/faster approaches are welcome :)\r\n\r\n    # install/load packages\r\n    if (!require(\"pacman\")) install.packages(\"pacman\")\r\n    pacman::p_load(data.table, RSQLite)\r\n    \r\n    # Set path and database name\r\n    path <- \"./data\"\r\n    setwd(path)\r\n    sqlite <- dbDriver(\"SQLite\")\r\n    con <- dbConnect(sqlite, \"20160920_kgl_Bosch.sqlite3\")\r\n    \r\n    # Loop through all csv files in path and write them to SQLight\r\n    for (file in list.files(pattern = \"*.csv\")){\r\n      print(Sys.time())\r\n      print(file)\r\n      data <- fread(file)\r\n      tbl_name <- gsub(\".csv\",\"\", file)\r\n      \r\n      if (dbExistsTable(con, tbl_name) == FALSE){\r\n        dbWriteTable(con, tbl_name, data)\r\n      }\r\n      \r\n      # Create an index on the Id-column to improve performance on later queries\r\n      dbSendQuery(con, paste0(\"CREATE UNIQUE INDEX idx_\", tbl_name, \" ON \", tbl_name, \"(Id)\"))\r\n      rm(data)\r\n      gc()\r\n    }",
      "votes": null
    },
    {
      "id": "136402",
      "postDate": "09/21/2016 19:28:38",
      "content": "<p>Word of advise -  don't use MYSQL. It has a hard column limit of ~4k columns (1000 columns with inno db)</p>",
      "rawMarkdown": "Word of advise -  don't use MYSQL. It has a hard column limit of ~4k columns (1000 columns with inno db)",
      "votes": null
    },
    {
      "id": "136560",
      "postDate": "09/22/2016 21:47:03",
      "content": "<p>@Daniel_Kuehn,</p>\n\n<p>Can you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?</p>\n\n<p>Thank you</p>",
      "rawMarkdown": "Daniel_Kuehn,\r\n\r\nCan you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?\r\n\r\nThank you",
      "votes": null
    },
    {
      "id": "136613",
      "postDate": "09/23/2016 11:23:34",
      "content": "<p>[quote=Chandrak1907;136560]</p>\n\n<p>@Daniel_Kuehn,</p>\n\n<p>Can you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?</p>\n\n<p>Thank you</p>\n\n<p>[/quote]</p>\n\n<p><s> Actually I didn't need to change max.number in this case, since I wrote each .csv file to a new table. SQLITE_MAX_COLUMN should be 2000 per table and non of the .csv files has more than 2k columns.</s>\nI guess dbWriteTable handles cases with more than 2000 columns per table, since it works for me without any problem. </p>\n\n<p>You can use joins on the Id column to retrieve all columns when you need them.\nE. g. try something like this to load the first 10k rows to R with all columns:</p>\n\n<pre><code>dbSendQuery(con, &quot;SELECT * \nFROM train_categorical As c \n    INNER JOIN train_date As d ON c.Id = d.Id\n    INNER JOIN train_numeric AS n ON c.Id = n.Id\nLIMIT 10000&quot;)\n</code></pre>",
      "rawMarkdown": "[quote=Chandrak1907;136560]\r\n\r\n@Daniel_Kuehn,\r\n\r\nCan you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?\r\n\r\nThank you\r\n\r\n[/quote]\r\n\r\n<s> Actually I didn't need to change max.number in this case, since I wrote each .csv file to a new table. SQLITE_MAX_COLUMN should be 2000 per table and non of the .csv files has more than 2k columns.</s>\r\nI guess dbWriteTable handles cases with more than 2000 columns per table, since it works for me without any problem. \r\n\r\nYou can use joins on the Id column to retrieve all columns when you need them.\r\nE. g. try something like this to load the first 10k rows to R with all columns:\r\n\r\n    dbSendQuery(con, \"SELECT * \r\n    FROM train_categorical As c \r\n        INNER JOIN train_date As d ON c.Id = d.Id\r\n        INNER JOIN train_numeric AS n ON c.Id = n.Id\r\n    LIMIT 10000\")",
      "votes": null
    },
    {
      "id": "136617",
      "postDate": "09/23/2016 12:49:54",
      "content": "<p>What I did was to normalize the database based on feature name to make the data-set &quot;longer&quot;  By parsing the name you can get a Station Value, Line Value, and Feature Value --then each measurement is characterized by those 3 numbers (and even add in the date)</p>\n\n<pre><code>Id     Value         L-Value     S-Value     F Value    Date\n 4     0.1           1           1           5          187.2\n 7    T1             2           3           89         192.6\n</code></pre>\n\n<p>Of course, my background is in Databases so this was a natural way to proceed...</p>\n\n<p>Then to get things like all the unique values for L2_S3_F89:</p>\n\n<pre><code>SELECT COUNT(1), VALUE, S-VALUE, F-VALUE FROM MY_TABLE\nWHERE L-VALUE=2 AND S-VALUE=3 AND F-VALUE=89\nGROUP BY L-VALUE,S-VALUE, F-VALUE\n</code></pre>",
      "rawMarkdown": "What I did was to normalize the database based on feature name to make the data-set \"longer\"  By parsing the name you can get a Station Value, Line Value, and Feature Value --then each measurement is characterized by those 3 numbers (and even add in the date)\r\n\r\n    Id     Value         L-Value     S-Value     F Value    Date\r\n     4     0.1           1           1           5          187.2\r\n     7    T1             2           3           89         192.6\r\n\r\nOf course, my background is in Databases so this was a natural way to proceed...\r\n\r\nThen to get things like all the unique values for L2_S3_F89:\r\n\r\n    SELECT COUNT(1), VALUE, S-VALUE, F-VALUE FROM MY_TABLE\r\n    WHERE L-VALUE=2 AND S-VALUE=3 AND F-VALUE=89\r\n    GROUP BY L-VALUE,S-VALUE, F-VALUE",
      "votes": null
    },
    {
      "id": "136662",
      "postDate": "09/23/2016 19:50:53",
      "content": "<p>@Daniel_Kuehn,</p>\n\n<p>Thank you for replying.\nAre you sure that train_categorical.csv has less than 2000 columns. When I read in first 100 rows , I see 2141 columns.</p>",
      "rawMarkdown": "Daniel_Kuehn,\r\n\r\nThank you for replying.\r\nAre you sure that train_categorical.csv has less than 2000 columns. When I read in first 100 rows , I see 2141 columns.",
      "votes": null
    },
    {
      "id": "136668",
      "postDate": "09/23/2016 20:12:04",
      "content": "<p>@Chandrak1907</p>\n\n<p>I see the same number and have seen that number tossed around as well.</p>\n\n<p>There was talk of some of the features not being in the test set (all NAN for that particular feature) but I do not know if that is enough to reduce below 2000.</p>",
      "rawMarkdown": "Chandrak1907\r\n\r\nI see the same number and have seen that number tossed around as well.\r\n\r\nThere was talk of some of the features not being in the test set (all NAN for that particular feature) but I do not know if that is enough to reduce below 2000.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 135805,
      "author_name": "datakungfu",
      "author_url": "",
      "post_date": "09/17/2016 05:05:00",
      "content": "<p>I'm experimenting with that route as well.  </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 135844,
      "author_name": "ievgenii1101",
      "author_url": "",
      "post_date": "09/17/2016 16:16:38",
      "content": "<p>Since you can't use SQL to build models and make any kind of predictive analysis anyway, why not using <em>data.table</em> in R? It is capable of handling way bigger datasets. And in some sense it behaves similar to SQL (you can also make joins, for example).\nIt took me 1 minute on a laptop to read &quot;test_numeric.csv&quot;. </p>\n\n<pre><code>require(data.table)\nrequire(bit64)\n\ntest = fread(&quot;test_numeric.csv&quot;)\n&gt; test = fread(&quot;test_numeric.csv&quot;)\nRead 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:01:08\n(of 969) columns from 1.991 GB file in 00:01:08\n\n&gt; dim(test)\n[1] 1183748     969\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 135943,
      "author_name": "rdslater",
      "author_url": "",
      "post_date": "09/18/2016 17:13:40",
      "content": "<p>Memory limits.  I only have 8GB of memory.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 135944,
      "author_name": "sandeepkumar",
      "author_url": "",
      "post_date": "09/18/2016 17:22:10",
      "content": "<p>Hi, </p>\n\n<p>I have used the same.I am getting the below error. </p>\n\n<p>test = fread(&quot;test_numeric.csv&quot;)</p>\n\n<p>Read 0.0% of 1183748 rows</p>\n\n<p>Error: cannot allocate vector of size 9.0 Mb</p>\n\n<p>In addition: There were 20 warnings (use warnings() to see them)</p>\n\n<p>Can someone help me to resolve this?</p>\n\n<p>Thank you.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 135947,
      "author_name": "sandeepkumar",
      "author_url": "",
      "post_date": "09/18/2016 17:45:41",
      "content": "<p>Now,I got it.I changes to :</p>\n\n<p>memory.limit(size=10000)</p>\n\n<p>Read 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:05:10</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136175,
      "author_name": "dkuehn",
      "author_url": "",
      "post_date": "09/20/2016 12:19:03",
      "content": "<p>Here is the script I used to load the data into SQLight. In case you don't have enough RAM to execute it, you could play with nrows and skip in fread() to process data in chunks. For this to work, you might need to write an additional INSERT-statement and execute it with dbSendQuery. Better/faster approaches are welcome :)</p>\n\n<pre><code># install/load packages\nif (!require(&quot;pacman&quot;)) install.packages(&quot;pacman&quot;)\npacman::p_load(data.table, RSQLite)\n\n# Set path and database name\npath &lt;- &quot;./data&quot;\nsetwd(path)\nsqlite &lt;- dbDriver(&quot;SQLite&quot;)\ncon &lt;- dbConnect(sqlite, &quot;20160920_kgl_Bosch.sqlite3&quot;)\n\n# Loop through all csv files in path and write them to SQLight\nfor (file in list.files(pattern = &quot;*.csv&quot;)){\n  print(Sys.time())\n  print(file)\n  data &lt;- fread(file)\n  tbl_name &lt;- gsub(&quot;.csv&quot;,&quot;&quot;, file)\n\n  if (dbExistsTable(con, tbl_name) == FALSE){\n    dbWriteTable(con, tbl_name, data)\n  }\n\n  # Create an index on the Id-column to improve performance on later queries\n  dbSendQuery(con, paste0(&quot;CREATE UNIQUE INDEX idx_&quot;, tbl_name, &quot; ON &quot;, tbl_name, &quot;(Id)&quot;))\n  rm(data)\n  gc()\n}\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136402,
      "author_name": "shivam6294",
      "author_url": "",
      "post_date": "09/21/2016 19:28:38",
      "content": "<p>Word of advise -  don't use MYSQL. It has a hard column limit of ~4k columns (1000 columns with inno db)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136560,
      "author_name": "chandrak",
      "author_url": "",
      "post_date": "09/22/2016 21:47:03",
      "content": "<p>@Daniel_Kuehn,</p>\n\n<p>Can you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?</p>\n\n<p>Thank you</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136613,
      "author_name": "dkuehn",
      "author_url": "",
      "post_date": "09/23/2016 11:23:34",
      "content": "<p>[quote=Chandrak1907;136560]</p>\n\n<p>@Daniel_Kuehn,</p>\n\n<p>Can you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?</p>\n\n<p>Thank you</p>\n\n<p>[/quote]</p>\n\n<p><s> Actually I didn't need to change max.number in this case, since I wrote each .csv file to a new table. SQLITE_MAX_COLUMN should be 2000 per table and non of the .csv files has more than 2k columns.</s>\nI guess dbWriteTable handles cases with more than 2000 columns per table, since it works for me without any problem. </p>\n\n<p>You can use joins on the Id column to retrieve all columns when you need them.\nE. g. try something like this to load the first 10k rows to R with all columns:</p>\n\n<pre><code>dbSendQuery(con, &quot;SELECT * \nFROM train_categorical As c \n    INNER JOIN train_date As d ON c.Id = d.Id\n    INNER JOIN train_numeric AS n ON c.Id = n.Id\nLIMIT 10000&quot;)\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136617,
      "author_name": "rdslater",
      "author_url": "",
      "post_date": "09/23/2016 12:49:54",
      "content": "<p>What I did was to normalize the database based on feature name to make the data-set &quot;longer&quot;  By parsing the name you can get a Station Value, Line Value, and Feature Value --then each measurement is characterized by those 3 numbers (and even add in the date)</p>\n\n<pre><code>Id     Value         L-Value     S-Value     F Value    Date\n 4     0.1           1           1           5          187.2\n 7    T1             2           3           89         192.6\n</code></pre>\n\n<p>Of course, my background is in Databases so this was a natural way to proceed...</p>\n\n<p>Then to get things like all the unique values for L2_S3_F89:</p>\n\n<pre><code>SELECT COUNT(1), VALUE, S-VALUE, F-VALUE FROM MY_TABLE\nWHERE L-VALUE=2 AND S-VALUE=3 AND F-VALUE=89\nGROUP BY L-VALUE,S-VALUE, F-VALUE\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136662,
      "author_name": "chandrak",
      "author_url": "",
      "post_date": "09/23/2016 19:50:53",
      "content": "<p>@Daniel_Kuehn,</p>\n\n<p>Thank you for replying.\nAre you sure that train_categorical.csv has less than 2000 columns. When I read in first 100 rows , I see 2141 columns.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 136668,
      "author_name": "rdslater",
      "author_url": "",
      "post_date": "09/23/2016 20:12:04",
      "content": "<p>@Chandrak1907</p>\n\n<p>I see the same number and have seen that number tossed around as well.</p>\n\n<p>There was talk of some of the features not being in the test set (all NAN for that particular feature) but I do not know if that is enough to reduce below 2000.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "134063": "I know all the cool kids are going to the Hadoop cluster, but this data is THAT big =)\r\n\r\nAnyway it is big enough that I cannot load into memory--my first thought was putting it in a personal database--has anyone else thought along that line?  I got my start in traditional SQL dbs so it seemed natural to just load the data up and even manipulate it using that method to take advantage of hard drive space, rather than memory.\r\n\r\n\r\nAnyone else approaching it that way?  I went postgresql and got the numeric data loaded pretty quick (a few minutes).",
    "135805": "I'm experimenting with that route as well.",
    "135844": "Since you can't use SQL to build models and make any kind of predictive analysis anyway, why not using *data.table* in R? It is capable of handling way bigger datasets. And in some sense it behaves similar to SQL (you can also make joins, for example).\r\nIt took me 1 minute on a laptop to read \"test_numeric.csv\". \r\n\r\n    require(data.table)\r\n    require(bit64)\r\n\r\n    test = fread(\"test_numeric.csv\")\r\n    > test = fread(\"test_numeric.csv\")\r\n    Read 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:01:08\r\n    (of 969) columns from 1.991 GB file in 00:01:08\r\n\r\n    > dim(test)\r\n    [1] 1183748     969",
    "135943": "Memory limits.  I only have 8GB of memory.",
    "135944": "Hi, \r\n\r\nI have used the same.I am getting the below error. \r\n\r\ntest = fread(\"test_numeric.csv\")\r\n\r\nRead 0.0% of 1183748 rows\r\n\r\nError: cannot allocate vector of size 9.0 Mb\r\n\r\nIn addition: There were 20 warnings (use warnings() to see them)\r\n\r\n\r\n\r\nCan someone help me to resolve this?\r\n\r\n\r\nThank you.",
    "135947": "Now,I got it.I changes to :\r\n\r\nmemory.limit(size=10000)\r\n\r\nRead 1183748 rows and 969 (of 969) columns from 1.991 GB file in 00:05:10",
    "136175": "Here is the script I used to load the data into SQLight. In case you don't have enough RAM to execute it, you could play with nrows and skip in fread() to process data in chunks. For this to work, you might need to write an additional INSERT-statement and execute it with dbSendQuery. Better/faster approaches are welcome :)\r\n\r\n    # install/load packages\r\n    if (!require(\"pacman\")) install.packages(\"pacman\")\r\n    pacman::p_load(data.table, RSQLite)\r\n    \r\n    # Set path and database name\r\n    path <- \"./data\"\r\n    setwd(path)\r\n    sqlite <- dbDriver(\"SQLite\")\r\n    con <- dbConnect(sqlite, \"20160920_kgl_Bosch.sqlite3\")\r\n    \r\n    # Loop through all csv files in path and write them to SQLight\r\n    for (file in list.files(pattern = \"*.csv\")){\r\n      print(Sys.time())\r\n      print(file)\r\n      data <- fread(file)\r\n      tbl_name <- gsub(\".csv\",\"\", file)\r\n      \r\n      if (dbExistsTable(con, tbl_name) == FALSE){\r\n        dbWriteTable(con, tbl_name, data)\r\n      }\r\n      \r\n      # Create an index on the Id-column to improve performance on later queries\r\n      dbSendQuery(con, paste0(\"CREATE UNIQUE INDEX idx_\", tbl_name, \" ON \", tbl_name, \"(Id)\"))\r\n      rm(data)\r\n      gc()\r\n    }",
    "136402": "Word of advise -  don't use MYSQL. It has a hard column limit of ~4k columns (1000 columns with inno db)",
    "136560": "Daniel_Kuehn,\r\n\r\nCan you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?\r\n\r\nThank you",
    "136613": "[quote=Chandrak1907;136560]\r\n\r\n@Daniel_Kuehn,\r\n\r\nCan you pls advise how did you change max.number of columns in  sqlite? Did you recompile your sqlite?\r\n\r\nThank you\r\n\r\n[/quote]\r\n\r\n<s> Actually I didn't need to change max.number in this case, since I wrote each .csv file to a new table. SQLITE_MAX_COLUMN should be 2000 per table and non of the .csv files has more than 2k columns.</s>\r\nI guess dbWriteTable handles cases with more than 2000 columns per table, since it works for me without any problem. \r\n\r\nYou can use joins on the Id column to retrieve all columns when you need them.\r\nE. g. try something like this to load the first 10k rows to R with all columns:\r\n\r\n    dbSendQuery(con, \"SELECT * \r\n    FROM train_categorical As c \r\n        INNER JOIN train_date As d ON c.Id = d.Id\r\n        INNER JOIN train_numeric AS n ON c.Id = n.Id\r\n    LIMIT 10000\")",
    "136617": "What I did was to normalize the database based on feature name to make the data-set \"longer\"  By parsing the name you can get a Station Value, Line Value, and Feature Value --then each measurement is characterized by those 3 numbers (and even add in the date)\r\n\r\n    Id     Value         L-Value     S-Value     F Value    Date\r\n     4     0.1           1           1           5          187.2\r\n     7    T1             2           3           89         192.6\r\n\r\nOf course, my background is in Databases so this was a natural way to proceed...\r\n\r\nThen to get things like all the unique values for L2_S3_F89:\r\n\r\n    SELECT COUNT(1), VALUE, S-VALUE, F-VALUE FROM MY_TABLE\r\n    WHERE L-VALUE=2 AND S-VALUE=3 AND F-VALUE=89\r\n    GROUP BY L-VALUE,S-VALUE, F-VALUE",
    "136662": "Daniel_Kuehn,\r\n\r\nThank you for replying.\r\nAre you sure that train_categorical.csv has less than 2000 columns. When I read in first 100 rows , I see 2141 columns.",
    "136668": "Chandrak1907\r\n\r\nI see the same number and have seen that number tossed around as well.\r\n\r\nThere was talk of some of the features not being in the test set (all NAN for that particular feature) but I do not know if that is enough to reduce below 2000."
  },
  "source": "meta"
}