@@ -298,6 +298,7 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
298298 unsigned name_size = 0 ;
299299 grn_column_flags flags = 0 ;
300300 VALUE rb_name , rb_value_type ;
301+ VALUE rb_value_size , rb_value_var_size ;
301302 VALUE options , rb_path , rb_persistent , rb_compress , rb_type , rb_with_weight ;
302303 VALUE rb_weight_float32 ;
303304 VALUE rb_missing_mode ;
@@ -319,6 +320,8 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
319320 "path" , & rb_path ,
320321 "persistent" , & rb_persistent ,
321322 "type" , & rb_type ,
323+ "value_size" , & rb_value_size ,
324+ "value_var_size" , & rb_value_var_size ,
322325 "with_weight" , & rb_with_weight ,
323326 "compress" , & rb_compress ,
324327 "weight_float32" , & rb_weight_float32 ,
@@ -420,8 +423,58 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
420423 rb_grn_inspect (rb_invalid_mode ));
421424 }
422425
423- column = grn_column_create (context , table , name , name_size ,
424- path , flags , value_type );
426+ if (rb_grn_context_implement_db (context )) {
427+ column = grn_column_create (context , table , name , name_size ,
428+ path , flags , value_type );
429+ } else {
430+ char fullname [GRN_TABLE_MAX_KEY_SIZE ];
431+ unsigned int fullname_size ;
432+ int table_name_len = strlen (fullname );
433+ if (name_size + 1 + table_name_len > GRN_TABLE_MAX_KEY_SIZE ) {
434+ rb_raise (rb_eArgError ,
435+ "[column][create] too long column name: required name_size(%d) < %d"
436+ ": <%.*s>.<%.*s>" ,
437+ name_size , GRN_TABLE_MAX_KEY_SIZE - 1 - table_name_len ,
438+ table_name_len , fullname , name_size , name );
439+ }
440+ // fullname[table_name_len] = '.';
441+ // grn_memcpy(fullname + table_name_len + 1, name, name_size);
442+ // fullname_size = table_name_len + 1 + name_size;
443+ // grn_ctx *target_ctx = context;
444+ // grn_id id = GRN_ID_NIL;
445+ // id = grn_pat_add(target_ctx,
446+ // target_ctx->impl->temporary_columns,
447+ // fullname, fullname_size,
448+ // NULL,
449+ // &added);
450+ // id |= GRN_OBJ_TMP_OBJECT | GRN_OBJ_TMP_COLUMN;
451+
452+ if (RVAL2CBOOL (rb_value_var_size ))
453+ flags |= GRN_OBJ_KEY_VAR_SIZE ;
454+ int64_t value_size = 0 ;
455+ if (!NIL_P (rb_value_size ))
456+ value_size = NUM2INT (rb_value_size );
457+
458+ grn_obj * res ;
459+ switch (flags & GRN_OBJ_COLUMN_TYPE_MASK ) {
460+ case GRN_OBJ_COLUMN_SCALAR :
461+ if ((flags & GRN_OBJ_KEY_VAR_SIZE ) || value_size > sizeof (int64_t )) {
462+ res = (grn_obj * )grn_ja_create (context , path , value_size , flags );
463+ } else {
464+ res = (grn_obj * )grn_ra_create (context , path , value_size , flags );
465+ }
466+ break ;
467+ case GRN_OBJ_COLUMN_VECTOR :
468+ res = (grn_obj * )grn_ja_create (context , path , value_size * 30 /*todo*/ , flags );
469+ //todo : zlib support
470+ break ;
471+ case GRN_OBJ_COLUMN_INDEX :
472+ res = (grn_obj * )grn_ii_create (context , path , table , flags ); //todo : ii layout support
473+ break ;
474+ }
475+ column = res ;
476+ }
477+
425478 if (context -> rc ) {
426479 VALUE rb_related_object ;
427480 rb_related_object =
0 commit comments