OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser::DDLStmt Class Referenceabstract

#include <ParserNode.h>

+ Inheritance diagram for Parser::DDLStmt:
+ Collaboration diagram for Parser::DDLStmt:

Public Member Functions

virtual void execute (const Catalog_Namespace::SessionInfo &session)=0
 
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Detailed Description

Definition at line 744 of file ParserNode.h.

Member Function Documentation

void Parser::DDLStmt::setColumnDescriptor ( ColumnDescriptor cd,
const ColumnDef coldef 
)

Definition at line 2972 of file ParserNode.cpp.

References Parser::SQLType::check_type(), ColumnDescriptor::columnName, ColumnDescriptor::columnType, g_use_date_in_days_default_encoding, Parser::SQLType::get_array_size(), Parser::ColumnDef::get_column_constraint(), Parser::ColumnDef::get_column_name(), Parser::ColumnDef::get_column_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), Parser::ColumnDef::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), Parser::CompressDef::get_encoding_name(), Parser::CompressDef::get_encoding_param(), Parser::SQLType::get_is_array(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), Parser::ColumnConstraintDef::get_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_output_srid(), Parser::SQLType::get_param1(), Parser::SQLType::get_param2(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_precision(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_subtype(), Parser::SQLType::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal(), IS_GEO, SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string_array(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_time(), ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, kARRAY, kBIGINT, kDATE, kDECIMAL, kENCODING_DATE_IN_DAYS, kENCODING_DICT, kENCODING_DIFF, kENCODING_FIXED, kENCODING_GEOINT, kENCODING_NONE, kENCODING_RL, kENCODING_SPARSE, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, SQLTypeInfoCore< TYPE_FACET_PACK >::set_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_fixed_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_input_srid(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_output_srid(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_subtype(), SQLTypeInfoCore< TYPE_FACET_PACK >::set_type(), Parser::SQLType::to_string(), and run_benchmark_import::type.

2972  {
2973  cd.columnName = *coldef->get_column_name();
2974  SQLType* t = coldef->get_column_type();
2975  t->check_type();
2976  if (t->get_is_array()) {
2978  cd.columnType.set_subtype(t->get_type());
2979  } else {
2980  cd.columnType.set_type(t->get_type());
2981  }
2982  if (IS_GEO(t->get_type())) {
2983  cd.columnType.set_subtype(static_cast<SQLTypes>(t->get_param1()));
2984  cd.columnType.set_input_srid(t->get_param2());
2985  cd.columnType.set_output_srid(t->get_param2());
2986  } else {
2987  cd.columnType.set_dimension(t->get_param1());
2988  cd.columnType.set_scale(t->get_param2());
2989  }
2991  const ColumnConstraintDef* cc = coldef->get_column_constraint();
2992  if (cc == nullptr) {
2993  cd.columnType.set_notnull(false);
2994  } else {
2995  cd.columnType.set_notnull(cc->get_notnull());
2996  }
2997  const CompressDef* compression = coldef->get_compression();
2998  if (compression == nullptr) {
2999  // Change default TEXT column behaviour to be DICT encoded
3000  if (cd.columnType.is_string() || cd.columnType.is_string_array()) {
3001  // default to 32-bits
3003  cd.columnType.set_comp_param(32);
3004  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 4) {
3006  cd.columnType.set_comp_param(16);
3007  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 9) {
3009  cd.columnType.set_comp_param(32);
3010  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
3011  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
3012  } else if (cd.columnType.is_geometry() && cd.columnType.get_output_srid() == 4326) {
3013  // default to GEOINT 32-bits
3015  cd.columnType.set_comp_param(32);
3016  } else if (type == kDATE && g_use_date_in_days_default_encoding) {
3017  // Days encoding for DATE
3019  cd.columnType.set_comp_param(0);
3020  } else {
3022  cd.columnType.set_comp_param(0);
3023  }
3024  } else {
3025  const std::string& comp = *compression->get_encoding_name();
3026  int comp_param;
3027  if (boost::iequals(comp, "fixed")) {
3028  if (!cd.columnType.is_integer() && !cd.columnType.is_time() &&
3029  !cd.columnType.is_decimal()) {
3030  throw std::runtime_error(
3031  cd.columnName +
3032  ": Fixed encoding is only supported for integer or time columns.");
3033  }
3034  // fixed-bits encoding
3035  if (type == kARRAY) {
3036  type = cd.columnType.get_subtype();
3037  }
3038  switch (type) {
3039  case kSMALLINT:
3040  if (compression->get_encoding_param() != 8) {
3041  throw std::runtime_error(
3042  cd.columnName +
3043  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
3044  }
3045  break;
3046  case kINT:
3047  if (compression->get_encoding_param() != 8 &&
3048  compression->get_encoding_param() != 16) {
3049  throw std::runtime_error(
3050  cd.columnName +
3051  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
3052  }
3053  break;
3054  case kBIGINT:
3055  if (compression->get_encoding_param() != 8 &&
3056  compression->get_encoding_param() != 16 &&
3057  compression->get_encoding_param() != 32) {
3058  throw std::runtime_error(cd.columnName +
3059  ": Compression parameter for Fixed encoding on "
3060  "BIGINT must be 8 or 16 or 32.");
3061  }
3062  break;
3063  case kTIMESTAMP:
3064  case kTIME:
3065  if (compression->get_encoding_param() != 32) {
3066  throw std::runtime_error(cd.columnName +
3067  ": Compression parameter for Fixed encoding on "
3068  "TIME or TIMESTAMP must be 32.");
3069  } else if (cd.columnType.is_high_precision_timestamp()) {
3070  throw std::runtime_error(
3071  "Fixed encoding is not supported for TIMESTAMP(3|6|9).");
3072  }
3073  break;
3074  case kDECIMAL:
3075  case kNUMERIC:
3076  if (compression->get_encoding_param() != 32 &&
3077  compression->get_encoding_param() != 16) {
3078  throw std::runtime_error(cd.columnName +
3079  ": Compression parameter for Fixed encoding on "
3080  "DECIMAL must be 16 or 32.");
3081  }
3082 
3083  if (compression->get_encoding_param() == 32 &&
3084  cd.columnType.get_precision() > 9) {
3085  throw std::runtime_error(
3086  cd.columnName + ": Precision too high for Fixed(32) encoding, max 9.");
3087  }
3088 
3089  if (compression->get_encoding_param() == 16 &&
3090  cd.columnType.get_precision() > 4) {
3091  throw std::runtime_error(
3092  cd.columnName + ": Precision too high for Fixed(16) encoding, max 4.");
3093  }
3094  break;
3095  case kDATE:
3096  if (compression->get_encoding_param() != 32 &&
3097  compression->get_encoding_param() != 16) {
3098  throw std::runtime_error(cd.columnName +
3099  ": Compression parameter for Fixed encoding on "
3100  "DATE must be 16 or 32.");
3101  }
3102  break;
3103  default:
3104  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
3105  t->to_string());
3106  }
3107  if (type == kDATE) {
3109  cd.columnType.set_comp_param(16);
3110  } else {
3112  cd.columnType.set_comp_param(compression->get_encoding_param());
3113  }
3114  } else if (boost::iequals(comp, "rl")) {
3115  // run length encoding
3117  cd.columnType.set_comp_param(0);
3118  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
3119  } else if (boost::iequals(comp, "diff")) {
3120  // differential encoding
3122  cd.columnType.set_comp_param(0);
3123  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
3124  } else if (boost::iequals(comp, "dict")) {
3125  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
3126  throw std::runtime_error(
3127  cd.columnName +
3128  ": Dictionary encoding is only supported on string or string array columns.");
3129  }
3130  if (compression->get_encoding_param() == 0) {
3131  comp_param = 32; // default to 32-bits
3132  } else {
3133  comp_param = compression->get_encoding_param();
3134  }
3135  if (cd.columnType.is_string_array() && comp_param != 32) {
3136  throw std::runtime_error(cd.columnName +
3137  ": Compression parameter for string arrays must be 32");
3138  }
3139  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
3140  throw std::runtime_error(
3141  cd.columnName +
3142  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
3143  }
3144  // diciontary encoding
3146  cd.columnType.set_comp_param(comp_param);
3147  } else if (boost::iequals(comp, "NONE")) {
3148  if (cd.columnType.is_geometry()) {
3150  cd.columnType.set_comp_param(64);
3151  } else {
3152  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
3153  throw std::runtime_error(
3154  cd.columnName +
3155  ": None encoding is only supported on string or string array columns.");
3156  }
3158  cd.columnType.set_comp_param(0);
3159  }
3160  } else if (boost::iequals(comp, "sparse")) {
3161  // sparse column encoding with mostly NULL values
3162  if (cd.columnType.get_notnull()) {
3163  throw std::runtime_error(
3164  cd.columnName + ": Cannot do sparse column encoding on a NOT NULL column.");
3165  }
3166  if (compression->get_encoding_param() == 0 ||
3167  compression->get_encoding_param() % 8 != 0 ||
3168  compression->get_encoding_param() > 48) {
3169  throw std::runtime_error(
3170  cd.columnName +
3171  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
3172  "sparse-column encoding.");
3173  }
3175  cd.columnType.set_comp_param(compression->get_encoding_param());
3176  // throw std::runtime_error("SPARSE encoding not supported yet.");
3177  } else if (boost::iequals(comp, "compressed")) {
3178  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
3179  throw std::runtime_error(
3180  cd.columnName +
3181  ": COMPRESSED encoding is only supported on WGS84 geo columns.");
3182  }
3183  if (compression->get_encoding_param() == 0) {
3184  comp_param = 32; // default to 32-bits
3185  } else {
3186  comp_param = compression->get_encoding_param();
3187  }
3188  if (comp_param != 32) {
3189  throw std::runtime_error(cd.columnName +
3190  ": only 32-bit COMPRESSED geo encoding is supported");
3191  }
3192  // encoding longitude/latitude as integers
3194  cd.columnType.set_comp_param(comp_param);
3195  } else if (boost::iequals(comp, "days")) {
3196  // days encoding for dates
3197  if (cd.columnType.get_type() != kDATE) {
3198  throw std::runtime_error(cd.columnName +
3199  ": Days encoding is only supported for DATE columns.");
3200  }
3201  if (compression->get_encoding_param() != 32 &&
3202  compression->get_encoding_param() != 16) {
3203  throw std::runtime_error(cd.columnName +
3204  ": Compression parameter for Days encoding on "
3205  "DATE must be 16 or 32.");
3206  }
3208  cd.columnType.set_comp_param((compression->get_encoding_param() == 16) ? 16 : 0);
3209  } else {
3210  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
3211  comp);
3212  }
3213  }
3214  if (cd.columnType.is_string_array() &&
3216  throw std::runtime_error(
3217  cd.columnName +
3218  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
3219  }
3220  if (t->get_is_array()) {
3221  int s = -1;
3222  auto array_size = t->get_array_size();
3223  if (array_size > 0) {
3224  auto sti = cd.columnType.get_elem_type();
3225  s = array_size * sti.get_size();
3226  if (s <= 0) {
3227  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
3228  }
3229  }
3230  cd.columnType.set_size(s);
3231 
3232  } else {
3234  }
3235  cd.isSystemCol = false;
3236  cd.isVirtualCol = false;
3237 }
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:332
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
SQLTypes
Definition: sqltypes.h:41
void set_size(int s)
Definition: sqltypes.h:424
void set_input_srid(int d)
Definition: sqltypes.h:420
HOST DEVICE int get_size() const
Definition: sqltypes.h:336
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:416
void set_fixed_size()
Definition: sqltypes.h:425
void set_dimension(int d)
Definition: sqltypes.h:418
void set_scale(int s)
Definition: sqltypes.h:421
void set_compression(EncodingType c)
Definition: sqltypes.h:426
void set_notnull(bool n)
Definition: sqltypes.h:423
void set_output_srid(int s)
Definition: sqltypes.h:422
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:417
bool g_use_date_in_days_default_encoding
Definition: ParserNode.cpp:67
bool is_time() const
Definition: sqltypes.h:483
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:333
bool is_geometry() const
Definition: sqltypes.h:489
Definition: sqltypes.h:56
bool is_integer() const
Definition: sqltypes.h:479
void set_comp_param(int p)
Definition: sqltypes.h:427
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:327
bool is_string() const
Definition: sqltypes.h:477
int get_precision() const
Definition: sqltypes.h:329
Definition: sqltypes.h:48
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659
SQLTypeInfo columnType
bool is_decimal() const
Definition: sqltypes.h:480
std::string columnName
#define IS_GEO(T)
Definition: sqltypes.h:167
bool is_string_array() const
Definition: sqltypes.h:478

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: