Changeset: be14d3144751 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=be14d3144751
Added Files:
        sql/backends/monet5/miniseed/79_registrar.mal
        sql/backends/monet5/miniseed/79_registrar.sql
        sql/backends/monet5/miniseed/registrar.c
        sql/backends/monet5/miniseed/registrar.h
        sql/backends/monet5/miniseed/registrar.mal
Branch: DVframework
Log Message:

Added: registrar module.


diffs (truncated from 820 to 300 lines):

diff --git a/sql/backends/monet5/miniseed/79_registrar.mal 
b/sql/backends/monet5/miniseed/79_registrar.mal
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/miniseed/79_registrar.mal
@@ -0,0 +1,20 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2012 MonetDB B.V.
+# All Rights Reserved.
+
+# This announces the miniseed module to the MAL interpreter
+library registrar;
+include registrar;
diff --git a/sql/backends/monet5/miniseed/79_registrar.sql 
b/sql/backends/monet5/miniseed/79_registrar.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/miniseed/79_registrar.sql
@@ -0,0 +1,63 @@
+/*
+The contents of this file are subject to the MonetDB Public License
+Version 1.1 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+http://www.monetdb.org/Legal/MonetDBLicense
+
+Software distributed under the License is distributed on an "AS IS"
+basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+License for the specific language governing rights and limitations
+under the License.
+
+The Original Code is the MonetDB Database System.
+
+The Initial Developer of the Original Code is CWI.
+Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+Copyright August 2008-2012 MonetDB B.V.
+All Rights Reserved.
+*/
+
+-- Register a repository
+-- CREATE FUNCTION get_tables_of_schema(schema_name string)
+-- RETURNS table
+-- BEGIN
+--     RETURN SELECT t.id, t.name FROM _tables AS t, schemas AS s WHERE s.name 
= schema_name AND s.id = t.schema_id;
+-- END; 
+-- 
+-- 
+-- CREATE FUNCTION get_columns_of_table(table_id integer)
+-- RETURNS table
+-- BEGIN
+--     RETURN SELECT c.name, c.type, c.number FROM _columns AS c WHERE 
c.table_id = table_id;
+-- END;
+
+
+CREATE PROCEDURE register_repo(repo string)
+external name registrar.register_repo;
+
+-- CREATE FUNCTION register_read(repo string)
+-- RETURNS bigint external name registrar.register_read;
+-- 
+-- CREATE FUNCTION mseed_register_fil(ticket bigint)
+-- RETURNS table(file_location string, dataquality char, network string, 
station string, location string, channel string, encoding tinyint, byte_order 
boolean) external name registrar.mseed_register_fil;
+-- 
+-- CREATE FUNCTION mseed_register_cat(ticket bigint)
+-- RETURNS table(file_location string, seq_no integer, record_length integer, 
start_time timestamp, frequency double, sample_count bigint, sample_type char) 
external name registrar.mseed_register_cat;
+-- 
+-- CREATE PROCEDURE mseed_register_repo(repo string)
+-- BEGIN
+--     DECLARE ticket BIGINT;
+--     SET ticket = register_read(repo);
+--     INSERT INTO mseed.files SELECT * FROM mseed_register_fil(ticket);
+--     INSERT INTO mseed.catalog SELECT * FROM mseed_register_cat(ticket);
+--     register_cleanup(ticket);
+-- END;
+
+
+
+
+
+
+
+
+
diff --git a/sql/backends/monet5/miniseed/registrar.c 
b/sql/backends/monet5/miniseed/registrar.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/miniseed/registrar.c
@@ -0,0 +1,665 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "monetdb_config.h"
+
+#include "registrar.h"
+//#include "vault.h"
+#include "mtime.h"
+
+#include "sql_mvc.h"
+#include "sql.h"
+
+/*
+ * keeps BAT and other properties of columns of a table.
+ */
+typedef struct {
+       bat *column_bats; //keeps bats of the columns: lower array
+       str *column_names; // names of columns that are kept in the higher array
+       str *column_types_strs; // type strings of columns
+} temp_subcontainer;
+
+/*
+ * keeps (some) tables of a schema.
+ */
+typedef struct {
+       str schema_name; //schema or vault name
+       temp_subcontainer *tables_columns; //keeps tables: higher array
+       str *table_names; //names of tables that are kept in the higher array
+       int *num_columns; //number of columns in each table in the higher array
+       sht num_tables;
+} temp_container;
+
+lng get_line_num(str filename);
+lng get_file_paths(str repo_path, str** ret_file_paths);
+str mseed_create_temp_container(temp_container* ret_tc);
+str mseed_register(str file_path, temp_container* ret_tc);
+int concatenate_strs(str* words_to_concat, int num_words_to_concat, str* 
ret_concatenated);
+str prepare_insertion(Client cntxt, temp_container* tc);
+str insert_into_vault(Client cntxt, MalBlkPtr mb, temp_container* tc);
+str SQLstatementIntern(Client c, str *expr, str nme, int execute, bit output);
+
+/*
+ * returns number of lines in a file.
+ * 
+ * WARNING: always counts EOF as a line. So proper return is taken if the file 
does 
+ * not have a newline at the end.
+ */
+lng get_line_num(str filename)
+{
+       FILE *f;
+       char c;
+       long lines = 0;
+       
+       f = fopen(filename, "r");
+       
+       if(f == NULL)
+               return 0;
+       
+       while((c = fgetc(f)) != EOF)
+               if(c == '\n')
+                       lines++;
+               
+       fclose(f);
+       
+       if(c != '\n')
+               lines++;
+       
+       return lines;
+}
+
+/*
+ * returns number of file_paths in repo_path.
+ * 
+ * stores each file_path in ret_file_paths.
+ * 
+ * repo_path may be either a file that is containing file_paths in the repo 
one per line,
+ * or a (recursive) directory containing the repository. 
+ * 
+ * TODO: if a directory path is given, traverse the directory recursively and 
collect all the files.
+ */
+lng get_file_paths(str repo_path, str** ret_file_paths)
+{
+       long num_file_paths = 0;
+       struct stat s;
+       str* file_paths = NULL;
+       if( stat(repo_path,&s) == 0 )
+       {
+               if( s.st_mode & S_IFDIR )
+               {
+                       //it's a directory
+                       //traverse and collect all the files
+               }
+               else if( s.st_mode & S_IFREG )
+               {
+                       //it's a file
+                       //each line is a file_path
+                       
+                       FILE *file;
+                       num_file_paths = get_line_num(repo_path);
+                       printf("num_file_paths: %ld\n", num_file_paths);
+                       
+                       *ret_file_paths = file_paths = (str*) 
GDKmalloc(num_file_paths * sizeof(str));
+                       assert(file_paths != NULL);
+                       
+                       file = fopen (repo_path, "r");
+                       
+                       if ( file != NULL )
+                       {
+                               char line [255]; /* or other suitable maximum 
line size */
+                               long i = 0;
+                               while ( fgets ( line, sizeof(line), file ) != 
NULL ) /* read a line */
+                               {
+                                       int len_line = strlen(line);
+                                       //                      if(len_line == 
1)
+                                       //                              
continue;
+                                       if(line[len_line-1] == '\n') 
+                                               line[len_line-1] = '\0';
+                                       file_paths[i] = GDKstrdup(line);
+                                       i++;
+                               }
+                               fclose ( file );
+                       }
+                       else
+                       {
+                               perror ( repo_path ); /* why didn't the file 
open? */
+                       }
+               }
+               else
+               {
+                       //something else
+                       return -1;
+               }
+       }
+       else
+       {
+               //error
+               return -1;
+       }
+       
+       return num_file_paths;
+       
+}
+
+/*
+ * fills the temp_container structure with the "mseed" metadata tables' info.
+ * 
+ * returns error or MAL_SUCCEED
+ * 
+ * TODO: This function is now hardcoding every info. It can be made generic, 
+ * because required info is in sql_catalog.
+ */
+str mseed_create_temp_container(temp_container* ret_tc)
+{
+       // cat: (metadata) catalog, fil: (metadata) files.
+       int num_tables = 2;
+       int num_c_fil = 8;
+       int num_c_cat = 7;
+       int c, t;
+       
+       str sch_name = "mseed";
+       
+       str cn_fil[] = {"file_location", "dataquality", "network", "station", 
"location", "channel", "encoding", "byte_order"};
+       str cn_cat[] = {"file_location", "seq_no", "record_length", 
"start_time", "frequency", "sample_count", "sample_type"};
+       
+       str cts_fil[] = {"string", "char", "string", "string", "string", 
"string", "tinyint", "boolean"};
+       str cts_cat[] = {"string", "int", "int", "timestamp", "double", 
"bigint", "char"};
+       
+       sht ct_fil[] = {TYPE_str, TYPE_str, TYPE_str, TYPE_str, TYPE_str, 
TYPE_str, TYPE_bte, TYPE_bit};
+       sht ct_cat[] = {TYPE_str, TYPE_int, TYPE_int, TYPE_timestamp, TYPE_dbl, 
TYPE_lng, TYPE_str};
+       
+       str tn[] = {"files", "catalog"};
+       int num_c[] = {8, 7};
+       
+       bat *cb_fil = (bat*)GDKmalloc(num_c_fil*sizeof(bat));
+       
+       bat *cb_cat = (bat*)GDKmalloc(num_c_cat*sizeof(bat));
+       
+       temp_subcontainer *tscs = 
(temp_subcontainer*)GDKmalloc(num_tables*sizeof(temp_subcontainer));
+       
+       BAT *aBAT;
+       
+       assert(cb_fil!=NULL);
+       assert(cb_cat!=NULL);
+       assert(tscs!=NULL);
+       
+       //cb_fil
+       for(c = 0; c < num_c_fil; c++)
+       {
+               aBAT = BATnew(TYPE_void, ct_fil[c], 0); //create empty BAT for 
each column.
+               if ( aBAT == NULL)
+                       
throw(MAL,"mseed_create_temp_container",MAL_MALLOC_FAIL);
+               BATseqbase(aBAT, 0);
+               if ( aBAT == NULL)
+                       
throw(MAL,"mseed_create_temp_container",MAL_MALLOC_FAIL);
+               BBPkeepref(cb_fil[c] = aBAT->batCacheid);
+       }
+       
+       //cb_cat
+       for(c = 0; c < num_c_cat; c++)
+       {
+               aBAT = BATnew(TYPE_void, ct_cat[c], 0); //create empty BAT for 
each column.
+               if ( aBAT == NULL)
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to