OmniSciDB  29e35f4d58
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

◆ execute()

◆ setColumnDescriptor()

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

Definition at line 2971 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.

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

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