Example #1
0
char *
exp_name( sql_exp *e )
{
	if (e->name)
		return e->name;
	if (e->type == e_convert && e->l)
		return exp_name(e->l);
	return NULL;
}
Example #2
0
char *
exp_func_name( sql_exp *e )
{
	if (e->type == e_func && e->f) {
		sql_subfunc *f = e->f;
		return f->func->base.name;
	}
	if (e->name)
		return e->name;
	if (e->type == e_convert && e->l)
		return exp_name(e->l);
	return NULL;
}
Example #3
0
int main()
{   
    std::string exp_name("100");

	unsigned int size = 2600;

    // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
    boost::posix_time::ptime epoch = boost::posix_time::ptime(boost::gregorian::date(1970,1,1));

    

    ///////////////////////// This section needs to be added to any other file.
    Chunk temp_chunk;
    std::deque <Chunk > *ssl_deque;
    ssl_deque = new std::deque <Chunk >[1];
    pthread_t thread_t;
    //struct SSL_ARG_STRUCT ssl_td = {ssl_deque, SSL_comm};
    struct SSL_ARG_STRUCT ssl_td = {ssl_deque, SSL_COMM()};

    int rc;
    rc = pthread_create(&thread_t, NULL, Thread_Transfer_Data, &ssl_td);
    if (rc)
    {
        std::cout << "Error: unable to create USB thread," << rc << std::endl;
        exit(-1);
    }
    /////////////////////////

    std::complex<float> *dev0_data;
    std::complex<float> *dev1_data;
    dev0_data = new std::complex<float> [size];
    dev1_data = new std::complex<float> [size];
    float pos[3];

    float xmin=-5.0;
    float xmax=5.0;
    float ymin=0.0;
    float ymax=10.0;
    float zmin=0.0;
    float zmax=2.0;


    int x=0;
    int y=1;
    int z=2;

    int batch_size = 5000;

    int run_duration = 5;
    time_t stop = time(0) + run_duration;
    time_t now = time(0);
    int i = 0;

    float stepsize = (xmax - xmin) / (static_cast <float> (batch_size));


    // while (now < stop) {
    //     fprintf(stderr, "sending batch %d\n", i);
    srand(time(NULL));

        float x_value = -5.0;

        for(unsigned int j = 0; j < batch_size; j++) {  
            // usleep(75000);
            usleep(4000);
            boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::universal_time();

            // for(unsigned int i = 0; i < 3; i++){
            //     // temp_chunk.traj[i] = 1.0;
            //     temp_chunk.traj[i] = 23423.12;
            // }

            // temp_chunk.traj[x] = xmin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(xmax-xmin)));
            // temp_chunk.traj[y] = ymin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(ymax-ymin)));
            // temp_chunk.traj[z] = zmin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(zmax-zmin)));


            temp_chunk.traj[x] = x_value;
            temp_chunk.traj[y] = 5 + static_cast <float> (ymax/2.0 * cos(x_value));
            temp_chunk.traj[z] = zmin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(zmax-zmin)));
            
            x_value = x_value + stepsize;

            for(unsigned int i = 0; i < size; i ++)
            {
                dev0_data[i] = std::complex<float>(i+1.23, size - i);
                dev1_data[i] = std::complex<float>(i+1.23, size - i);

                temp_chunk.dev0_data[i] = dev0_data[i];
                temp_chunk.dev1_data[i] = dev1_data[i];
            }
            temp_chunk.num_dev = 100;
            std::string temp_name =  "user02";
            for(unsigned int i = 0; i<temp_name.length(); i++){
                temp_chunk.file_name[i] = temp_name[i];
            }
            temp_chunk.time = t1;


            // boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
            // boost::this_thread::sleep(boost::posix_time::millisec(500));
            // boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
            // boost::posix_time::time_duration msdiff = epoch - now;
            // long timestamp = msdiff.total_milliseconds();

            // time_t seconds; 
            // time(&seconds); 
            // unsigned long long millis = (unsigned long long)seconds * 1000;

            // temp_chunk.timestamp = millis;

            // boost::posix_time::ptime t2 = boost::posix_time::microsec_clock::universal_time();
            // boost::posix_time::time_duration diff = t2 - epoch;
            // unsigned long long diff_time = diff.total_microseconds();
            // std::cout << j << " chunk timestamp " << t2 << std::endl;


            boost::posix_time::ptime ts = boost::posix_time::microsec_clock::universal_time();
            std::string ts_str = boost::posix_time::to_simple_string(ts);
            temp_chunk.timestamp = ts_str.c_str();


            // struct timeval tv;

            // gettimeofday(&tv, NULL);

            // unsigned long long millisecondsSinceEpoch =
            //     (unsigned long long)(tv.tv_sec) * 1000 +
            //     (unsigned long long)(tv.tv_usec) / 1000;

            // printf("%llu\n", millisecondsSinceEpoch);





            // auto epoch = std::chrono::system_clock::from_time_t(0);
            // auto now = std::chrono::high_resolution_clock::now();
            // auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch).count();
            // temp_chunk.timestamp = timestamp;
            // temp_chunk.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - std::chrono::system_clock::from_time_t(0)).count();

            ///////////////////////// This section needs to be added to any other file.
            pthread_mutex_lock(&mtx_ssl);
            ssl_td.ssl_deque[0].push_back(temp_chunk);
            pthread_cond_signal(&cond_ssl);
            pthread_mutex_unlock(&mtx_ssl);
            /////////////////////////

            boost::posix_time::ptime t2 = boost::posix_time::microsec_clock::universal_time();
            boost::posix_time::time_duration diff = t2 - t1;
            long diff_time = diff.total_microseconds();
            std::cout << j << " ssl duration " << t2 << std::endl;
        }

    //     now = time(0);
    //     usleep(2500000);    // half 1/4 sec
    //     i = i + 1;

    // }







    quit_now = true;

    usleep(1000000);

    delete [] dev0_data;
    delete [] dev1_data;
    delete [] ssl_deque;

    return 0;
}
Example #4
0
/* return val;
 */
static list * 
rel_psm_return( mvc *sql, sql_subtype *restype, list *restypelist, symbol *return_sym )
{
	exp_kind ek = {type_value, card_value, FALSE};
	sql_exp *res;
	sql_rel *rel = NULL;
	int is_last = 0;
	list *l = sa_list(sql->sa);

	if (restypelist)
		ek.card = card_relation;
	res = rel_value_exp2(sql, &rel, return_sym, sql_sel, ek, &is_last);
	if (!res)
		return NULL;
	if (ek.card != card_relation && (!res || 
           	(res = rel_check_type(sql, restype, res, type_equal)) == NULL))
		return NULL;
	else if (ek.card == card_relation && !rel)
		return NULL;
	
	if (rel && ek.card != card_relation)
		append(l, exp_rel(sql, rel));
	else if (rel && !is_ddl(rel->op)) {
		list *exps = sa_list(sql->sa);
		node *n, *m;
		int isproject = (rel->op == op_project);
		list *oexps = rel->exps;
		sql_rel *l = rel->l;

		if (is_topn(rel->op))
			oexps = l->exps;
		for (n = oexps->h, m = restypelist->h; n && m; n = n->next, m = m->next) {
			sql_exp *e = n->data;
			sql_arg *ce = m->data;
			char *cname = exp_name(e);
			char name[16];

			if (!cname)
				cname = sa_strdup(sql->sa, number2name(name, 16, ++sql->label));
			if (!isproject) 
				e = exp_column(sql->sa, exp_relname(e), cname, exp_subtype(e), exp_card(e), has_nil(e), is_intern(e));
			e = rel_check_type(sql, &ce->type, e, type_equal);
			if (!e)
				return NULL;
			append(exps, e);
		}
		if (isproject)
			rel -> exps = exps;
		else
			rel = rel_project(sql->sa, rel, exps);
		res = exp_rel(sql, rel);
	} else if (rel && restypelist){ /* handle return table-var */
		list *exps = sa_list(sql->sa);
		sql_table *t = rel_ddl_table_get(rel);
		node *n, *m;
		char *tname = t->base.name;

		if (cs_size(&t->columns) != list_length(restypelist))
			return sql_error(sql, 02, "RETURN: number of columns do not match");
		for (n = t->columns.set->h, m = restypelist->h; n && m; n = n->next, m = m->next) {
			sql_column *c = n->data;
			sql_arg *ce = m->data;
			sql_exp *e = exp_alias(sql->sa, tname, c->base.name, tname, c->base.name, &c->type, CARD_MULTI, c->null, 0);

			e = rel_check_type(sql, &ce->type, e, type_equal);
			if (!e)
				return NULL;
			append(exps, e);
		}
		rel = rel_project(sql->sa, rel, exps);
		res = exp_rel(sql, rel);
	}
	append(l, exp_return(sql->sa, res, stack_nr_of_declared_tables(sql)));
	return l;
}
Example #5
0
/* SET variable = value and set (variable1, .., variableN) = (query) */
static sql_exp *
psm_set_exp(mvc *sql, dnode *n)
{
	symbol *val = n->next->data.sym;
	sql_exp *e = NULL;
	int level = 0, is_last = 0;
	sql_subtype *tpe = NULL;
	sql_rel *rel = NULL;
	sql_exp *res = NULL;
	int single = (n->type == type_string);


	if (single) {
		exp_kind ek = {type_value, card_value, FALSE};
		const char *name = n->data.sval;
		/* name can be 
			'parameter of the function' (ie in the param list)
			or a local or global variable, declared earlier
		*/

		/* check if variable is known from the stack */
		if (!stack_find_var(sql, name)) {
			sql_arg *a = sql_bind_param(sql, name);

			if (!a) /* not parameter, ie local var ? */
				return sql_error(sql, 01, SQLSTATE(42000) "Variable %s unknown", name);
			tpe = &a->type;
		} else { 
			tpe = stack_find_type(sql, name);
		}

		e = rel_value_exp2(sql, &rel, val, sql_sel, ek, &is_last);
		if (!e || (rel && e->card > CARD_AGGR))
			return NULL;

		level = stack_find_frame(sql, name);
		e = rel_check_type(sql, tpe, e, type_cast); 
		if (!e)
			return NULL;
		if (rel) {
			sql_exp *er = exp_rel(sql, rel);
			list *b = sa_list(sql->sa);

			append(b, er);
			append(b, exp_set(sql->sa, name, e, level));
			res = exp_rel(sql, rel_psm_block(sql->sa, b));
		} else {
			res = exp_set(sql->sa, name, e, level);
		}
	} else { /* multi assignment */
		exp_kind ek = {type_value, (single)?card_column:card_relation, FALSE};
		sql_rel *rel_val = rel_subquery(sql, NULL, val, ek, APPLY_JOIN);
		dlist *vars = n->data.lval;
		dnode *m;
		node *n;
		list *b;

		if (!rel_val || !is_project(rel_val->op) ||
			    dlist_length(vars) != list_length(rel_val->exps)) {
			return sql_error(sql, 02, SQLSTATE(42000) "SET: Number of variables not equal to number of supplied values");
		}

	       	b = sa_list(sql->sa);
		if (rel_val) {
			sql_exp *er = exp_rel(sql, rel_val);

			append(b, er);
		}

		for(m = vars->h, n = rel_val->exps->h; n && m; n = n->next, m = m->next) {
			char *vname = m->data.sval;
			sql_exp *v = n->data;

			if (!stack_find_var(sql, vname)) {
				sql_arg *a = sql_bind_param(sql, vname);

				if (!a) /* not parameter, ie local var ? */
					return sql_error(sql, 01, SQLSTATE(42000) "Variable %s unknown", vname);
				tpe = &a->type;
			} else { 
				tpe = stack_find_type(sql, vname);
			}

			if (!exp_name(v))
				exp_label(sql->sa, v, ++sql->label);
			v = exp_column(sql->sa, exp_relname(v), exp_name(v), exp_subtype(v), v->card, has_nil(v), is_intern(v));

			level = stack_find_frame(sql, vname);
			v = rel_check_type(sql, tpe, v, type_cast); 
			if (!v)
				return NULL;
			if (v->card > CARD_AGGR) {
				sql_subaggr *zero_or_one = sql_bind_aggr(sql->sa, sql->session->schema, "zero_or_one", exp_subtype(v));
				assert(zero_or_one);
				v = exp_aggr1(sql->sa, v, zero_or_one, 0, 0, CARD_ATOM, 0);
			}
			append(b, exp_set(sql->sa, vname, v, level));
		}
		res = exp_rel(sql, rel_psm_block(sql->sa, b));
	}
	return res;
}
Example #6
0
sql_exp *
exp_copy( sql_allocator *sa, sql_exp * e)
{
	sql_exp *l, *r, *r2, *ne = NULL;

	switch(e->type){
	case e_column:
		ne = exp_column(sa, e->l, e->r, exp_subtype(e), e->card, has_nil(e), is_intern(e));
		ne->flag = e->flag;
		break;
	case e_cmp:
		if (e->flag == cmp_or) {
			list *l = exps_copy(sa, e->l);
			list *r = exps_copy(sa, e->r);
			if (l && r)
				ne = exp_or(sa, l,r);
		} else if (e->flag == cmp_in || e->flag == cmp_notin || get_cmp(e) == cmp_filter) {
			sql_exp *l = exp_copy(sa, e->l);
			list *r = exps_copy(sa, e->r);

			if (l && r) {
				if (get_cmp(e) == cmp_filter)
					ne = exp_filter(sa, l, r, e->f, is_anti(e));
				else
					ne = exp_in(sa, l, r, e->flag);
			}
		} else {
			l = exp_copy(sa, e->l);
			r = exp_copy(sa, e->r);

			if (e->f) {
				r2 = exp_copy(sa, e->f);
				if (l && r && r2)
					ne = exp_compare2(sa, l, r, r2, e->flag);
			} else if (l && r) {
				ne = exp_compare(sa, l, r, e->flag);
			}
		}
		break;
	case e_convert:
		l = exp_copy(sa, e->l);
		if (l)
			ne = exp_convert(sa, l, exp_fromtype(e), exp_totype(e));
		break;
	case e_aggr:
	case e_func: {
		list *l = e->l, *nl = NULL;

		if (!l) {
			return e;
		} else {
			nl = exps_copy(sa, l);
			if (!nl)
				return NULL;
		}
		if (e->type == e_func)
			ne = exp_op(sa, nl, e->f);
		else 
			ne = exp_aggr(sa, nl, e->f, need_distinct(e), need_no_nil(e), e->card, has_nil(e));
		break;
	}	
	case e_atom:
		if (e->l)
			ne = exp_atom(sa, e->l);
		else if (!e->r)
			ne = exp_atom_ref(sa, e->flag, &e->tpe);
		else 
			ne = exp_param(sa, e->r, &e->tpe, e->flag);
		break;
	case e_psm:
		if (e->flag == PSM_SET) 
			ne = exp_set(sa, e->name, exp_copy(sa, e->l), GET_PSM_LEVEL(e->flag));
		break;
	}
	if (ne && e->p)
		ne->p = prop_copy(sa, e->p);
	if (e->name)
		exp_setname(sa, ne, exp_find_rel_name(e), exp_name(e));
	return ne;
}