Changeset: 4d29f6f5e2e6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4d29f6f5e2e6
Modified Files:
        sql/backends/monet5/vaults/lidar/75_lidar.sql
        sql/backends/monet5/vaults/lidar/lidar.c
        sql/backends/monet5/vaults/lidar/lidar.h
        sql/backends/monet5/vaults/lidar/lidar.mal
Branch: data-vaults
Log Message:

Add checkTable and Analyze table so tables are populated on the first selection 
(point or range selection). Add new bind functions for lidar data to be used in 
the new MAP plan re-written by datavault optimizer. Split the loadTable into a 
wrapper and loader so we can use the loaded during checkTables in case the 
table was not yet loaded.


diffs (truncated from 577 to 300 lines):

diff --git a/sql/backends/monet5/vaults/lidar/75_lidar.sql 
b/sql/backends/monet5/vaults/lidar/75_lidar.sql
--- a/sql/backends/monet5/vaults/lidar/75_lidar.sql
+++ b/sql/backends/monet5/vaults/lidar/75_lidar.sql
@@ -2,3 +2,5 @@ create procedure lidarattach(fname strin
 create procedure lidarattach(fname string, tname string) external name 
lidar.attach;
 create procedure lidarload(tname string) external name lidar.load;
 create procedure lidarexport(tname string, fname string, format string) 
external name lidar.export;
+create procedure lidarchecktab(tname string) external name lidar.checktab;
+create procedure lidaranalyzetab(status int, tname string) external name 
lidar.analyzetab;
diff --git a/sql/backends/monet5/vaults/lidar/lidar.c 
b/sql/backends/monet5/vaults/lidar/lidar.c
--- a/sql/backends/monet5/vaults/lidar/lidar.c
+++ b/sql/backends/monet5/vaults/lidar/lidar.c
@@ -34,14 +34,17 @@
 #include <clients.h>
 #include <mal_exception.h>
 
+static MT_Lock mt_lidar_lock;
+
+#define LIDAR_LOCK MT_lock_set(&mt_lidar_lock) 
+#define LIDAR_UNLOCK MT_lock_unset(&mt_lidar_lock) 
+
 #define LIDAR_INS_COL "INSERT INTO lidar_columns(id, name, type, units, 
number, table_id) \
         VALUES(%d,'%s','%s','%s',%d,%d);"
 #define FILE_INS "INSERT INTO lidar_files(id, name) VALUES (%d, '%s');"
 #define DEL_TABLE "DELETE FROM lidarfiles;"
 #define ATTACHDIR "CALL lidarattach('%s');"
 
-static MT_Lock mt_lidar_lock;
-
 #ifndef NDEBUG
 static
 void print_lidar_header(FILE *file, LASHeaderH header, const char* file_name, 
int bSkipVLR, int bWKT) {
@@ -980,7 +983,7 @@ read_array_##BAT_TYPE(str fname,                            
                                
        BAT *b;                                                                 
                                        \
        BAT_TYPE *d = NULL;                                                     
                                \
        LASPointH p = NULL;                                                     
                                \
-       LASReaderH reader;                                                      
                                        \
+       LASReaderH reader = NULL;                                               
                                                \
        int i;                                                                  
                                                \
                                                                                
                                                        \
        b = BATnew(TYPE_void, TYPE_##BAT_TYPE, rows, PERSISTENT);               
\
@@ -1032,13 +1035,11 @@ READ_ARRAY(lng)
 READ_ARRAY(hge)
 #endif
 
-str LIDARloadTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+static
+str LIDARloadTable_(mvc *m, sql_schema *sch, sql_table *lidar_tbl, str tname)
 {
-       mvc *m = NULL;
-       sql_schema *sch;
-       sql_table *lidar_fl, *lidar_tbl, *lidar_cl, *tbl = NULL;
+       sql_table *lidar_fl, *lidar_cl, *tbl = NULL;
        sql_column *col, *colx, *coly, *colz;
-       str tname = toLower(*getArgReference_str(stk, pci, 1));
        str fname;
        str msg = MAL_SUCCEED;
        oid rid = oid_nil, frid = oid_nil, tid = oid_nil;
@@ -1049,36 +1050,10 @@ str LIDARloadTable(Client cntxt, MalBlkP
        int *tpcode = NULL;
        long *rep = NULL, *wid = NULL, rows;
        BAT *x = NULL, *y = NULL, *z = NULL;
-       size_t sz;
        int precisionx, precisiony, precisionz;
        double scalex, scaley, scalez;
        int error_code;
 
-       if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
-               return msg;
-       if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
-               return msg;
-       sch = mvc_bind_schema(m, "sys");
-
-       lidar_tbl = mvc_bind_table(m, sch, "lidar_tables");
-       if (lidar_tbl == NULL) {
-               msg = createException(MAL, "lidar.loadtable", "LIDAR catalog is 
missing.\n");
-               return msg;
-       }
-
-       tbl = mvc_bind_table(m, sch, tname);
-       if (tbl == NULL) {
-               msg = createException(MAL, "lidar.loadtable", "Could not find 
table %s.\n", tname);
-               return msg;
-       }
-
-       col = mvc_bind_column(m, tbl, "x");
-       sz = store_funcs.count_col(m->session->tr, col, 1);
-       if (sz != 0) {
-               msg = createException(MAL, "lidar.loadtable", "Table %s is not 
empty.\n", tname);
-               return msg;
-       }
-
        col = mvc_bind_column(m, lidar_tbl, "name");
        rid = table_funcs.column_find_row(m->session->tr, col, tname, NULL);
        if (rid == oid_nil) {
@@ -1252,6 +1227,45 @@ str LIDARloadTable(Client cntxt, MalBlkP
        return msg;
 }
 
+str LIDARloadTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+    mvc *m = NULL;
+    sql_table *lidar_tbl, *tbl;
+       sql_schema *sch;
+       str tname = toLower(*getArgReference_str(stk, pci, 1));
+    sql_column *col;
+       str msg = MAL_SUCCEED;
+       size_t sz;
+
+       if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
+               return msg;
+       if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
+               return msg;
+
+       sch = mvc_bind_schema(m, "sys");
+
+       lidar_tbl = mvc_bind_table(m, sch, "lidar_tables");
+       if (lidar_tbl == NULL) {
+               msg = createException(MAL, "lidar.loadtable", "LIDAR catalog is 
missing.\n");
+               return msg;
+       }
+
+    tbl = mvc_bind_table(m, sch, tname);
+       if (tbl == NULL) {
+               msg = createException(MAL, "lidar.loadtable", "Could not find 
table %s.\n", tname);
+               return msg;
+       }
+
+       col = mvc_bind_column(m, tbl, "x");
+       sz = store_funcs.count_col(m->session->tr, col, 1);
+       if (sz != 0) {
+               msg = createException(MAL, "lidar.loadtable", "Table %s is not 
empty.\n", tname);
+               return msg;
+       }
+
+       return LIDARloadTable_(m, sch, lidar_tbl, tname);
+}
+
 str
 LIDARprelude(void *ret) {
        (void) ret;
@@ -1259,3 +1273,344 @@ LIDARprelude(void *ret) {
 
        return MAL_SUCCEED;
 }
+
+str
+LIDARCheckTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+  mvc *m = NULL;
+  str msg = MAL_SUCCEED;
+  size_t sz;
+  sql_schema *sch = NULL;
+  sql_table *lidar_tbl, *tbl = NULL;
+  sql_column *col;
+  oid rid = oid_nil;
+  str tname = *getArgReference_str(stk, pci, 2);
+  int *res = getArgReference_int(stk, pci, 0);
+
+  if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
+    return msg;
+  if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
+    return msg;
+
+  sch = mvc_bind_schema(m, "sys");
+  lidar_tbl = mvc_bind_table(m, sch, "lidar_tables");
+  if (lidar_tbl == NULL) {
+    msg = createException(MAL, "lidar.check", "LIDAR catalog is missing.\n");
+    return msg;
+  }
+
+  /*Check if is a table which belongs to lidar_tables*/
+  col = mvc_bind_column(m, lidar_tbl, "name");
+  rid = table_funcs.column_find_row(m->session->tr, col, tname, NULL);
+  if (rid == oid_nil) {
+    return MAL_SUCCEED;
+  }
+
+  tbl = mvc_bind_table(m, sch, tname);
+  if (tbl == NULL) {
+    msg = createException(MAL, "lidar.check", "Could not find table %s.\n", 
tname);
+    return msg;
+  }
+
+  col = mvc_bind_column(m, tbl, "id");
+  sz = store_funcs.count_col(m->session->tr, col, 1);
+
+  if (sz == 0) {
+    /*Lets load the table*/
+    msg = LIDARloadTable_(m, sch, lidar_tbl, tname);
+    *res = LIDAR_TABLE_LOADED;
+  } else {
+    if (tbl->access == TABLE_WRITABLE)
+      *res = LIDAR_TABLE_ANALYZE;
+    else 
+      *res = LIDAR_TABLE_DONE;
+
+#ifndef NDEBUG
+    fprintf(stderr, "The table %s is already loaded and its status is 
%d!!!\n", tname, *res);
+#endif
+  }
+
+  return msg;
+}
+
+str
+LIDARAnalyzeTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+    mvc *m = NULL;
+    str msg = MAL_SUCCEED;
+    char readonly[BUFSIZ], analyze[BUFSIZ];
+    char *sr, *sa;
+    sql_schema *sch = NULL;
+    sql_table *lidar_tbl;
+    sql_column *col;
+    oid rid = oid_nil;
+    int status = *getArgReference_int(stk, pci, 2);
+    str tname = *getArgReference_str(stk, pci, 3);
+    int *res = getArgReference_int(stk, pci, 0);
+
+    if (status != LIDAR_TABLE_ANALYZE) {
+        *res = status;
+        return msg;
+    }
+
+    if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != MAL_SUCCEED)
+        return msg;
+    if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED)
+        return msg;
+
+    sch = mvc_bind_schema(m, "sys");
+    lidar_tbl = mvc_bind_table(m, sch, "lidar_tables");
+    if (lidar_tbl == NULL) {
+        msg = createException(MAL, "lidar.analyze", "LIDAR catalog is 
missing.\n");
+        return msg;
+    }
+
+    /*Check if is a table which belongs to lidar_tables*/
+    col = mvc_bind_column(m, lidar_tbl, "name");
+    rid = table_funcs.column_find_row(m->session->tr, col, tname, NULL);
+    if (rid == oid_nil) {
+        msg = createException(MAL, "lidar.analyze", "Table %s is unknown to 
the LIDAR catalog. Attach first the containing file\n", tname);
+        return msg;
+    }
+
+
+    /*Set table read only*/
+    sr = readonly;
+    snprintf(readonly, BUFSIZ, "alter table %s set read only;", tname);
+
+#ifndef NDEBUG
+    fprintf(stderr, "The readonly stmt is: %s!!!\n", readonly);
+#endif
+    LIDAR_LOCK;
+    msg = SQLstatementIntern(cntxt, &sr, "lidar.analyze", TRUE, FALSE, NULL);
+    LIDAR_UNLOCK;
+    if (msg)
+        return msg;
+
+    /*Analyze table*/
+    sa = analyze;
+    snprintf(analyze, BUFSIZ, "analyze sys.%s (id, posX, posY, posZ) minmax;", 
tname);
+
+#ifndef NDEBUG
+    fprintf(stderr, "The analyze stmt is: %s!!!\n", analyze);
+#endif
+    LIDAR_LOCK;
+    msg = SQLstatementIntern(cntxt, &sa, "lidar.analyze", TRUE, FALSE, NULL);
+    LIDAR_UNLOCK;
+    if (msg)
+        return msg;
+
+    *res = LIDAR_TABLE_DONE;
+
+    return MAL_SUCCEED;
+}
+
+static BAT * 
+mvc_bind(mvc *m, char *sname, char *tname, char *cname, int access)
+{
+    sql_trans *tr = m->session->tr;
+    BAT *b = NULL;
+    sql_schema *s = NULL;
+    sql_table *t = NULL;
+    sql_column *c = NULL;
+
+    s = mvc_bind_schema(m, sname);
+    if (s == NULL)
+        return NULL;
+    t = mvc_bind_table(m, s, tname);
+    if (t == NULL)
+        return NULL;
+    c = mvc_bind_column(m, t, cname);
+    if (c == NULL)
+        return NULL;
+
+    b = store_funcs.bind_col(tr, c, access);
+    return b;
+}
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to