Changeset: 1c284ed4b00d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c284ed4b00d
Modified Files:
        sql/backends/monet5/bamloader/bam_db_interface.c
        sql/backends/monet5/bamloader/bam_db_interface.h
        sql/backends/monet5/bamloader/bam_globals.h
        sql/backends/monet5/bamloader/bam_lib.c
        sql/backends/monet5/bamloader/bam_lib.h
        sql/backends/monet5/bamloader/bam_loader.c
        sql/backends/monet5/bamloader/bam_loader.h
        sql/backends/monet5/bamloader/bam_wrapper.c
        sql/backends/monet5/bamloader/bam_wrapper.h
Branch: bamloader
Log Message:

Layout.


diffs (truncated from 5460 to 300 lines):

diff --git a/sql/backends/monet5/bamloader/bam_db_interface.c 
b/sql/backends/monet5/bamloader/bam_db_interface.c
--- a/sql/backends/monet5/bamloader/bam_db_interface.c
+++ b/sql/backends/monet5/bamloader/bam_db_interface.c
@@ -19,13 +19,14 @@
 
 /*
  * (author) R Cijvat
- * The code in this file handles all communication that is done with the 
running database.
+ * The code in this file handles all communication that is done with
+ * the running database.
  */
 
 #include "monetdb_config.h"
 #include "bam_globals.h"
 #include "bam_db_interface.h"
-    
+
 #define SQL_CREATE_STORAGE_0 \
     "CREATE TABLE bam.alignments_"LLFMT" ( \n\
         virtual_offset                BIGINT      NOT NULL, \n\
@@ -52,7 +53,7 @@
         CONSTRAINT alignments_extra_"LLFMT"_fkey_virtual_offset FOREIGN KEY 
(virtual_offset) \n\
             REFERENCES bam.alignments_"LLFMT" (virtual_offset) \n\
     );"
-    
+
 #define SQL_CREATE_STORAGE_1 \
     "CREATE TABLE bam.paired_primary_alignments_"LLFMT" ( \n\
         l_virtual_offset              BIGINT      NOT NULL, \n\
@@ -161,13 +162,13 @@
     UNION ALL \n\
     SELECT * \n\
     FROM bam.unpaired_alignments_"LLFMT";"
-    
+
 #define SQL_DROP_HEADER \
     "DELETE FROM bam.pg WHERE file_id = "LLFMT";\n" \
     "DELETE FROM bam.rg WHERE file_id = "LLFMT";\n" \
     "DELETE FROM bam.sq WHERE file_id = "LLFMT";\n" \
     "DELETE FROM bam.files WHERE file_id = "LLFMT";\n"
-    
+
 #define SQL_DROP_STORAGE_0 \
     "DROP TABLE bam.alignments_extra_"LLFMT";\n" \
     "DROP TABLE bam.alignments_"LLFMT";\n"
@@ -180,8 +181,8 @@
     "DROP TABLE bam.paired_primary_alignments_"LLFMT";\n" \
     "DROP TABLE bam.paired_secondary_alignments_"LLFMT";\n" \
     "DROP TABLE bam.unpaired_alignments_"LLFMT";\n"
-    
-    
+
+
 
 #define SQL_COPY_INTO_FILES "COPY BINARY INTO bam.files FROM ('%s', '%s', 
'%s', '%s', '%s', '%s');\n"
 #define SQL_COPY_INTO_SQ    "COPY BINARY INTO bam.sq    FROM ('%s', '%s', 
'%s', '%s', '%s', '%s', '%s');\n"
@@ -193,9 +194,9 @@
 #define SQL_COPY_INTO_PAIRED_ALIGNMENTS "COPY BINARY INTO 
bam.paired_%s_alignments_"LLFMT" FROM \
     ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', \
      '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');\n"
-    
+
 #define SQL_COPY_INTO_ALIGNMENTS_EXTRA "COPY BINARY INTO 
bam.alignments_extra_"LLFMT" FROM ('%s', '%s', '%s', '%s');\n"
-    
+
 #define BUF_SIZE_CREATE_STORAGE_0 2048
 #define BUF_SIZE_CREATE_STORAGE_1 8192
 #define BUF_SIZE_DROP_FILE 1024
@@ -205,137 +206,172 @@
 
 
 /* Some buffers */
-char buf_sql_create_storage_0[BUF_SIZE_CREATE_STORAGE_0];
-char buf_sql_create_storage_1[BUF_SIZE_CREATE_STORAGE_1];
-char buf_sql_drop_file[BUF_SIZE_DROP_FILE];
-char buf_sql_copy_into[BUF_SIZE_COPY_INTO];
+static char buf_sql_create_storage_0[BUF_SIZE_CREATE_STORAGE_0];
+static char buf_sql_create_storage_1[BUF_SIZE_CREATE_STORAGE_1];
+static char buf_sql_drop_file[BUF_SIZE_DROP_FILE];
+static char buf_sql_copy_into[BUF_SIZE_COPY_INTO];
 
 
 
-str 
-create_schema_if_not_exists(Client cntxt, mvc *m, str schemaname, str descr, 
sql_schema **ret) {
-    sql_schema *result;
-    if((result = mvc_bind_schema(m, schemaname)) == NULL) {
-        char buf_sql_create_schema[64];
-        str sql_create_schema = buf_sql_create_schema;
-        str msg;
-        
-        snprintf(sql_create_schema, 64, "CREATE SCHEMA %s;", schemaname);
-        
-        TO_LOG("#<bam_loader> Creating schema '%s'...\n", schemaname);
-        RUN_SQL(cntxt, &sql_create_schema, descr, msg);
-        if(msg != MAL_SUCCEED) {
-            REUSE_EXCEPTION(msg, MAL, "create_schema_if_not_exists", "Could 
not create bam schema: %s", msg);
-            return msg;
-        }
-        if((result = mvc_bind_schema(m, schemaname)) == NULL) {
-            throw(MAL, "create_schema_if_not_exists", "Could not create bam 
schema");
-        }
-    }
-    if(ret) *ret = result;
-    return MAL_SUCCEED;
+str
+create_schema_if_not_exists(Client cntxt, mvc * m, str schemaname, str descr,
+                           sql_schema ** ret)
+{
+       sql_schema *result;
+
+       if ((result = mvc_bind_schema(m, schemaname)) == NULL) {
+               char buf_sql_create_schema[64];
+               str sql_create_schema = buf_sql_create_schema;
+               str msg;
+
+               snprintf(sql_create_schema, 64, "CREATE SCHEMA %s;",
+                        schemaname);
+
+               TO_LOG("#<bam_loader> Creating schema '%s'...\n", schemaname);
+               RUN_SQL(cntxt, &sql_create_schema, descr, msg);
+               if (msg != MAL_SUCCEED) {
+                       REUSE_EXCEPTION(msg, MAL,
+                                       "create_schema_if_not_exists",
+                                       "Could not create bam schema: %s",
+                                       msg);
+                       return msg;
+               }
+               if ((result = mvc_bind_schema(m, schemaname)) == NULL) {
+                       throw(MAL, "create_schema_if_not_exists",
+                             "Could not create bam schema");
+               }
+       }
+       if (ret)
+               *ret = result;
+       return MAL_SUCCEED;
 }
 
 
 /**
- * Function tries to bind to a table with the given name. If it fails (== 
NULL), it attempts to create the table. 
- * The function fails if a binding to the table is impossible, even after 
creation.
- * If the function succeeds, it adjusts the optionally given pointer to point 
to the binded sql_table.
+ * Function tries to bind to a table with the given name. If it fails
+ * (== NULL), it attempts to create the table.
+ * The function fails if a binding to the table is impossible, even
+ * after creation.  If the function succeeds, it adjusts the
+ * optionally given pointer to point to the binded sql_table.
  */
-str 
-create_table_if_not_exists(Client cntxt, mvc *m, sql_schema *s, str tablename, 
str sql_creation, str descr, sql_table **ret) {
-    sql_table *result;
-    str msg;
-    if((result = mvc_bind_table(m, s, tablename)) == NULL) {
-        TO_LOG("#<bam_loader> Creating table '%s'...\n", tablename);
+str
+create_table_if_not_exists(Client cntxt, mvc * m, sql_schema * s,
+                          str tablename, str sql_creation, str descr,
+                          sql_table ** ret)
+{
+       sql_table *result;
+       str msg;
 
-        RUN_SQL(cntxt, &sql_creation, descr, msg);
-        if(msg != MAL_SUCCEED) {
-            REUSE_EXCEPTION(msg, MAL, "create_table_if_not_exists", "Could not 
create table '%s': %s", tablename, msg);
-            return msg;
-        }
-        if((result = mvc_bind_table(m, s, tablename)) == NULL) {
-            throw(MAL, "create_table_if_not_exists", "Could not create table 
'%s'", tablename);
-        }
-    }
-    if(ret) *ret = result;
-    return MAL_SUCCEED;
+       if ((result = mvc_bind_table(m, s, tablename)) == NULL) {
+               TO_LOG("#<bam_loader> Creating table '%s'...\n", tablename);
+
+               RUN_SQL(cntxt, &sql_creation, descr, msg);
+               if (msg != MAL_SUCCEED) {
+                       REUSE_EXCEPTION(msg, MAL,
+                                       "create_table_if_not_exists",
+                                       "Could not create table '%s': %s",
+                                       tablename, msg);
+                       return msg;
+               }
+               if ((result = mvc_bind_table(m, s, tablename)) == NULL) {
+                       throw(MAL, "create_table_if_not_exists",
+                             "Could not create table '%s'", tablename);
+               }
+       }
+       if (ret)
+               *ret = result;
+       return MAL_SUCCEED;
 }
 
 
 /**
- * Function returns the highest file id that currently exists in the bam.files 
table and stores this number + 1 in the next_file_id
- * variable. Function doesn't use a mutex to guarantee that the returned value 
is up to date at return time. If this is required,
+ * Function returns the highest file id that currently exists in the
+ * bam.files table and stores this number + 1 in the next_file_id
+ * variable. Function doesn't use a mutex to guarantee that the
+ * returned value is up to date at return time. If this is required,
  * the calling function should activate a mutex.
  */
 str
-next_file_id(mvc *m, sql_table *files, lng *next_file_id)
+next_file_id(mvc * m, sql_table * files, lng * next_file_id)
 {
-    sql_column *c;
-    BAT *b = NULL;
-    BATiter li;
-    sht i;
-    BUN p = 0, q = 0;
-    lng max_file_id = 0;
-    
-    assert(m != NULL);
-    assert(files != NULL);
-    
-    /* Try to bind the file_id column of the bam.files table */
-    if((c = mvc_bind_column(m, files, "file_id")) == NULL) {
-        throw(MAL, "next_file_id", "Could not retrieve the next file id: Error 
binding file_id column of 'files' table");
-    }
-        
-    /* Loop through all BATs for this column, i.e. the real BAT and the delta 
BATs and find the maximum file_id */
-    for(i=0; i<3; ++i) {
-        b = store_funcs.bind_col(m->session->tr, c, i);
-        if(b != NULL) {
-            li = bat_iterator(b);
-            BATloop(b, p, q) {
-                lng t = *(lng *)BUNtail(li, p);
-                max_file_id = MAX(max_file_id, t);
-            }
-            BBPreleaseref(b->batCacheid);
-        }
-    }
-    *next_file_id = max_file_id+1;
-    return MAL_SUCCEED;
+       sql_column *c;
+       BAT *b = NULL;
+       BATiter li;
+       sht i;
+       BUN p = 0, q = 0;
+       lng max_file_id = 0;
+
+       assert(m != NULL);
+       assert(files != NULL);
+
+       /* Try to bind the file_id column of the bam.files table */
+       if ((c = mvc_bind_column(m, files, "file_id")) == NULL) {
+               throw(MAL, "next_file_id",
+                     "Could not retrieve the next file id: Error binding 
file_id column of 'files' table");
+       }
+
+       /* Loop through all BATs for this column, i.e. the real BAT
+        * and the delta BATs and find the maximum file_id */
+       for (i = 0; i < 3; ++i) {
+               b = store_funcs.bind_col(m->session->tr, c, i);
+               if (b != NULL) {
+                       li = bat_iterator(b);
+                       BATloop(b, p, q) {
+                               lng t = *(lng *) BUNtail(li, p);
+
+                               max_file_id = MAX(max_file_id, t);
+                       }
+                       BBPreleaseref(b->batCacheid);
+               }
+       }
+       *next_file_id = max_file_id + 1;
+       return MAL_SUCCEED;
 }
 
 str
-create_alignment_storage_0(Client cntxt, str descr, bam_wrapper *bw) {
-    str sql_create_storage = buf_sql_create_storage_0;
-    str msg;
-    snprintf(sql_create_storage, BUF_SIZE_CREATE_STORAGE_0, 
SQL_CREATE_STORAGE_0, 
-        bw->file_id, bw->file_id, bw->file_id, bw->file_id, bw->file_id, 
bw->file_id);
-    RUN_SQL(cntxt, &sql_create_storage, descr, msg);
-    if(msg != MAL_SUCCEED) {
-        REUSE_EXCEPTION(msg, MAL, "create_alignment_storage_0", 
-                         "Could not create alignment storage for file '%s' 
(file id '"LLFMT"'): %s",
-                         bw->file_location, bw->file_id, msg);
-    }
-    return msg;
+create_alignment_storage_0(Client cntxt, str descr, bam_wrapper * bw)
+{
+       str sql_create_storage = buf_sql_create_storage_0;
+       str msg;
+
+       snprintf(sql_create_storage, BUF_SIZE_CREATE_STORAGE_0,
+                SQL_CREATE_STORAGE_0, bw->file_id, bw->file_id, bw->file_id,
+                bw->file_id, bw->file_id, bw->file_id);
+       RUN_SQL(cntxt, &sql_create_storage, descr, msg);
+       if (msg != MAL_SUCCEED) {
+               REUSE_EXCEPTION(msg, MAL, "create_alignment_storage_0",
+                               "Could not create alignment storage for file 
'%s' (file id '"
+                               LLFMT "'): %s", bw->file_location,
+                               bw->file_id, msg);
+       }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to