int main(int argc, char** argv) { SyntaxAnalyzer SyntaxAnalyzer("../grammar_ch/grammar.txt"); SyntaxAnalyzer.buildLL1ParseTab(); cout << endl; SyntaxAnalyzer.ll1SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)*0"); cout << endl; SyntaxAnalyzer.ll1SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)0"); cout << endl; SyntaxAnalyzer.calLR1ItemSetFamily(); cout << endl; SyntaxAnalyzer.buildLR1ParseTab(); cout << endl; // SyntaxAnalyzer.lr1SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)*0"); cout << endl; // SyntaxAnalyzer.lr1SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)0"); cout << endl; // SyntaxAnalyzer.calLR0ItemSetFamily(); cout << endl; // SyntaxAnalyzer.buildLR0ParseTab(); cout << endl; // SyntaxAnalyzer.lr0SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)*0"); cout << endl; // SyntaxAnalyzer.lr0SyntaxAnalyze("0+(0+0*(0+(0+0+0*0*0)*0+0+(0+0)+0)+0)0"); cout << endl; // Z->AA // ->AaA // ->aAaA // ->aAaaA // ->abaaA // ->abaab return 0; }
std::unique_ptr<IMergeTreeIndex> minmaxIndexCreator( const NamesAndTypesList & new_columns, std::shared_ptr<ASTIndexDeclaration> node, const Context & context) { if (node->name.empty()) throw Exception("Index must have unique name", ErrorCodes::INCORRECT_QUERY); if (node->type->arguments) throw Exception("Minmax index have not any arguments", ErrorCodes::INCORRECT_QUERY); ASTPtr expr_list = MergeTreeData::extractKeyExpressionList(node->expr->clone()); auto syntax = SyntaxAnalyzer(context, {}).analyze( expr_list, new_columns); auto minmax_expr = ExpressionAnalyzer(expr_list, syntax, context).getActions(false); auto sample = ExpressionAnalyzer(expr_list, syntax, context) .getActions(true)->getSampleBlock(); Names columns; DataTypes data_types; for (size_t i = 0; i < expr_list->children.size(); ++i) { const auto & column = sample.getByPosition(i); columns.emplace_back(column.name); data_types.emplace_back(column.type); } return std::make_unique<MergeTreeMinMaxIndex>( node->name, std::move(minmax_expr), columns, data_types, sample, node->granularity); }
void StorageMerge::convertingSourceStream(const Block & header, const Context & context, ASTPtr & query, BlockInputStreamPtr & source_stream, QueryProcessingStage::Enum processed_stage) { Block before_block_header = source_stream->getHeader(); source_stream = std::make_shared<ConvertingBlockInputStream>(context, source_stream, header, ConvertingBlockInputStream::MatchColumnsMode::Name); ASTPtr where_expression = typeid_cast<ASTSelectQuery *>(query.get())->where_expression; if (!where_expression) return; for (size_t column_index : ext::range(0, header.columns())) { ColumnWithTypeAndName header_column = header.getByPosition(column_index); ColumnWithTypeAndName before_column = before_block_header.getByName(header_column.name); /// If the processed_stage greater than FetchColumns and the block structure between streams is different. /// the where expression maybe invalid because of convertingBlockInputStream. /// So we need to throw exception. if (!header_column.type->equals(*before_column.type.get()) && processed_stage > QueryProcessingStage::FetchColumns) { NamesAndTypesList source_columns = getSampleBlock().getNamesAndTypesList(); NameAndTypePair virtual_column = getColumn("_table"); source_columns.insert(source_columns.end(), virtual_column); auto syntax_result = SyntaxAnalyzer(context).analyze(where_expression, source_columns); ExpressionActionsPtr actions = ExpressionAnalyzer{where_expression, syntax_result, context}.getActions(false, false); Names required_columns = actions->getRequiredColumns(); for (const auto & required_column : required_columns) { if (required_column == header_column.name) throw Exception("Block structure mismatch in Merge Storage: different types:\n" + before_block_header.dumpStructure() + "\n" + header.dumpStructure(), ErrorCodes::BLOCKS_HAVE_DIFFERENT_STRUCTURE); } } } }