OmniSciDB  04ee39c94c
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 733 of file ParserNode.h.

Member Function Documentation

◆ execute()

◆ setColumnDescriptor()

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

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

2872  {
2873  cd.columnName = *coldef->get_column_name();
2874  SQLType* t = coldef->get_column_type();
2875  t->check_type();
2876  if (t->get_is_array()) {
2878  cd.columnType.set_subtype(t->get_type());
2879  } else {
2880  cd.columnType.set_type(t->get_type());
2881  }
2882  if (IS_GEO(t->get_type())) {
2883  cd.columnType.set_subtype(static_cast<SQLTypes>(t->get_param1()));
2884  cd.columnType.set_input_srid(t->get_param2());
2885  cd.columnType.set_output_srid(t->get_param2());
2886  } else {
2887  cd.columnType.set_dimension(t->get_param1());
2888  cd.columnType.set_scale(t->get_param2());
2889  }
2891  const ColumnConstraintDef* cc = coldef->get_column_constraint();
2892  if (cc == nullptr) {
2893  cd.columnType.set_notnull(false);
2894  } else {
2895  cd.columnType.set_notnull(cc->get_notnull());
2896  }
2897  const CompressDef* compression = coldef->get_compression();
2898  if (compression == nullptr) {
2899  // Change default TEXT column behaviour to be DICT encoded
2900  if (cd.columnType.is_string() || cd.columnType.is_string_array()) {
2901  // default to 32-bits
2903  cd.columnType.set_comp_param(32);
2904  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 4) {
2906  cd.columnType.set_comp_param(16);
2907  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 9) {
2909  cd.columnType.set_comp_param(32);
2910  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
2911  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
2912  } else if (cd.columnType.is_geometry() && cd.columnType.get_output_srid() == 4326) {
2913  // default to GEOINT 32-bits
2915  cd.columnType.set_comp_param(32);
2916  } else if (type == kDATE && g_use_date_in_days_default_encoding) {
2917  // Days encoding for DATE
2919  cd.columnType.set_comp_param(0);
2920  } else {
2922  cd.columnType.set_comp_param(0);
2923  }
2924  } else {
2925  const std::string& comp = *compression->get_encoding_name();
2926  int comp_param;
2927  if (boost::iequals(comp, "fixed")) {
2928  if (!cd.columnType.is_integer() && !cd.columnType.is_time() &&
2929  !cd.columnType.is_decimal()) {
2930  throw std::runtime_error(
2931  cd.columnName +
2932  ": Fixed encoding is only supported for integer or time columns.");
2933  }
2934  // fixed-bits encoding
2935  if (type == kARRAY) {
2936  type = cd.columnType.get_subtype();
2937  }
2938  switch (type) {
2939  case kSMALLINT:
2940  if (compression->get_encoding_param() != 8) {
2941  throw std::runtime_error(
2942  cd.columnName +
2943  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
2944  }
2945  break;
2946  case kINT:
2947  if (compression->get_encoding_param() != 8 &&
2948  compression->get_encoding_param() != 16) {
2949  throw std::runtime_error(
2950  cd.columnName +
2951  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
2952  }
2953  break;
2954  case kBIGINT:
2955  if (compression->get_encoding_param() != 8 &&
2956  compression->get_encoding_param() != 16 &&
2957  compression->get_encoding_param() != 32) {
2958  throw std::runtime_error(cd.columnName +
2959  ": Compression parameter for Fixed encoding on "
2960  "BIGINT must be 8 or 16 or 32.");
2961  }
2962  break;
2963  case kTIMESTAMP:
2964  case kTIME:
2965  if (compression->get_encoding_param() != 32) {
2966  throw std::runtime_error(cd.columnName +
2967  ": Compression parameter for Fixed encoding on "
2968  "TIME or TIMESTAMP must be 32.");
2969  } else if (cd.columnType.is_high_precision_timestamp()) {
2970  throw std::runtime_error(
2971  "Fixed encoding is not supported for TIMESTAMP(3|6|9).");
2972  }
2973  break;
2974  case kDECIMAL:
2975  case kNUMERIC:
2976  if (compression->get_encoding_param() != 32 &&
2977  compression->get_encoding_param() != 16) {
2978  throw std::runtime_error(cd.columnName +
2979  ": Compression parameter for Fixed encoding on "
2980  "DECIMAL must be 16 or 32.");
2981  }
2982 
2983  if (compression->get_encoding_param() == 32 &&
2984  cd.columnType.get_precision() > 9) {
2985  throw std::runtime_error(
2986  cd.columnName + ": Precision too high for Fixed(32) encoding, max 9.");
2987  }
2988 
2989  if (compression->get_encoding_param() == 16 &&
2990  cd.columnType.get_precision() > 4) {
2991  throw std::runtime_error(
2992  cd.columnName + ": Precision too high for Fixed(16) encoding, max 4.");
2993  }
2994  break;
2995  case kDATE:
2996  if (compression->get_encoding_param() != 32 &&
2997  compression->get_encoding_param() != 16) {
2998  throw std::runtime_error(cd.columnName +
2999  ": Compression parameter for Fixed encoding on "
3000  "DATE must be 16 or 32.");
3001  }
3002  break;
3003  default:
3004  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
3005  t->to_string());
3006  }
3007  if (type == kDATE) {
3009  cd.columnType.set_comp_param(16);
3010  } else {
3012  cd.columnType.set_comp_param(compression->get_encoding_param());
3013  }
3014  } else if (boost::iequals(comp, "rl")) {
3015  // run length encoding
3017  cd.columnType.set_comp_param(0);
3018  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
3019  } else if (boost::iequals(comp, "diff")) {
3020  // differential encoding
3022  cd.columnType.set_comp_param(0);
3023  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
3024  } else if (boost::iequals(comp, "dict")) {
3025  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
3026  throw std::runtime_error(
3027  cd.columnName +
3028  ": Dictionary encoding is only supported on string or string array columns.");
3029  }
3030  if (compression->get_encoding_param() == 0) {
3031  comp_param = 32; // default to 32-bits
3032  } else {
3033  comp_param = compression->get_encoding_param();
3034  }
3035  if (cd.columnType.is_string_array() && comp_param != 32) {
3036  throw std::runtime_error(cd.columnName +
3037  ": Compression parameter for string arrays must be 32");
3038  }
3039  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
3040  throw std::runtime_error(
3041  cd.columnName +
3042  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
3043  }
3044  // diciontary encoding
3046  cd.columnType.set_comp_param(comp_param);
3047  } else if (boost::iequals(comp, "NONE")) {
3048  if (cd.columnType.is_geometry()) {
3050  cd.columnType.set_comp_param(64);
3051  } else {
3052  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
3053  throw std::runtime_error(
3054  cd.columnName +
3055  ": None encoding is only supported on string or string array columns.");
3056  }
3058  cd.columnType.set_comp_param(0);
3059  }
3060  } else if (boost::iequals(comp, "sparse")) {
3061  // sparse column encoding with mostly NULL values
3062  if (cd.columnType.get_notnull()) {
3063  throw std::runtime_error(
3064  cd.columnName + ": Cannot do sparse column encoding on a NOT NULL column.");
3065  }
3066  if (compression->get_encoding_param() == 0 ||
3067  compression->get_encoding_param() % 8 != 0 ||
3068  compression->get_encoding_param() > 48) {
3069  throw std::runtime_error(
3070  cd.columnName +
3071  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
3072  "sparse-column encoding.");
3073  }
3075  cd.columnType.set_comp_param(compression->get_encoding_param());
3076  // throw std::runtime_error("SPARSE encoding not supported yet.");
3077  } else if (boost::iequals(comp, "compressed")) {
3078  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
3079  throw std::runtime_error(
3080  cd.columnName +
3081  ": COMPRESSED encoding is only supported on WGS84 geo columns.");
3082  }
3083  if (compression->get_encoding_param() == 0) {
3084  comp_param = 32; // default to 32-bits
3085  } else {
3086  comp_param = compression->get_encoding_param();
3087  }
3088  if (comp_param != 32) {
3089  throw std::runtime_error(cd.columnName +
3090  ": only 32-bit COMPRESSED geo encoding is supported");
3091  }
3092  // encoding longitude/latitude as integers
3094  cd.columnType.set_comp_param(comp_param);
3095  } else if (boost::iequals(comp, "days")) {
3096  // days encoding for dates
3097  if (cd.columnType.get_type() != kDATE) {
3098  throw std::runtime_error(cd.columnName +
3099  ": Days encoding is only supported for DATE columns.");
3100  }
3101  if (compression->get_encoding_param() != 32 &&
3102  compression->get_encoding_param() != 16) {
3103  throw std::runtime_error(cd.columnName +
3104  ": Compression parameter for Days encoding on "
3105  "DATE must be 16 or 32.");
3106  }
3108  cd.columnType.set_comp_param((compression->get_encoding_param() == 16) ? 16 : 0);
3109  } else {
3110  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
3111  comp);
3112  }
3113  }
3114  if (cd.columnType.is_string_array() &&
3116  throw std::runtime_error(
3117  cd.columnName +
3118  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
3119  }
3120  if (t->get_is_array()) {
3121  int s = -1;
3122  auto array_size = t->get_array_size();
3123  if (array_size > 0) {
3124  auto sti = cd.columnType.get_elem_type();
3125  s = array_size * sti.get_size();
3126  if (s <= 0) {
3127  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
3128  }
3129  }
3130  cd.columnType.set_size(s);
3131 
3132  } else {
3134  }
3135  cd.isSystemCol = false;
3136  cd.isVirtualCol = false;
3137 }
bool is_string_array() const
Definition: sqltypes.h:451
bool is_time() const
Definition: sqltypes.h:456
HOST DEVICE int get_size() const
Definition: sqltypes.h:333
int get_precision() const
Definition: sqltypes.h:326
Definition: sqltypes.h:51
SQLTypes
Definition: sqltypes.h:40
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:330
void set_size(int s)
Definition: sqltypes.h:421
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
void set_input_srid(int d)
Definition: sqltypes.h:417
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:413
void set_fixed_size()
Definition: sqltypes.h:422
void set_dimension(int d)
Definition: sqltypes.h:415
void set_scale(int s)
Definition: sqltypes.h:418
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_notnull(bool n)
Definition: sqltypes.h:420
void set_output_srid(int s)
Definition: sqltypes.h:419
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:414
bool g_use_date_in_days_default_encoding
Definition: ParserNode.cpp:64
bool is_integer() const
Definition: sqltypes.h:452
bool is_decimal() const
Definition: sqltypes.h:453
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:324
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:632
Definition: sqltypes.h:55
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:329
void set_comp_param(int p)
Definition: sqltypes.h:424
bool is_geometry() const
Definition: sqltypes.h:462
Definition: sqltypes.h:47
SQLTypeInfo columnType
std::string columnName
bool is_string() const
Definition: sqltypes.h:450
#define IS_GEO(T)
Definition: sqltypes.h:164
+ Here is the call graph for this function:

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