2011-08-28 02:22:23 +00:00
# pragma once
2010-06-24 19:12:10 +00:00
2019-01-14 18:15:04 +00:00
# include <optional>
2017-04-01 09:19:00 +00:00
# include <Parsers/ASTWithAlias.h>
2010-06-24 19:12:10 +00:00
namespace DB
{
2019-01-14 18:15:04 +00:00
/// Identifier (column, table or alias)
2014-07-03 22:39:13 +00:00
class ASTIdentifier : public ASTWithAlias
2010-06-24 19:12:10 +00:00
{
2018-09-20 13:13:33 +00:00
public :
2017-05-27 17:27:16 +00:00
/// name. The composite identifier here will have a concatenated name (of the form a.b.c), and individual components will be available inside the children.
2017-04-01 07:20:54 +00:00
String name ;
2011-08-28 02:22:23 +00:00
2019-01-15 12:28:17 +00:00
ASTIdentifier ( const String & name_ )
: name ( name_ )
, special ( false )
{
range = StringRange ( name . data ( ) , name . data ( ) + name . size ( ) ) ;
}
2011-09-25 03:37:09 +00:00
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
2018-12-07 12:34:40 +00:00
String getID ( char delim ) const override { return " Identifier " + ( delim + name ) ; }
2011-12-12 06:15:34 +00:00
2017-04-01 07:20:54 +00:00
ASTPtr clone ( ) const override { return std : : make_shared < ASTIdentifier > ( * this ) ; }
2013-08-13 08:54:28 +00:00
2017-04-01 07:20:54 +00:00
void collectIdentifierNames ( IdentifierNameSet & set ) const override
{
set . insert ( name ) ;
}
2015-08-05 21:38:31 +00:00
protected :
2017-04-01 07:20:54 +00:00
void formatImplWithoutAlias ( const FormatSettings & settings , FormatState & state , FormatStateStacked frame ) const override ;
2018-06-27 16:34:11 +00:00
void appendColumnNameImpl ( WriteBuffer & ostr ) const override ;
2018-09-20 13:13:33 +00:00
private :
2019-01-15 12:28:17 +00:00
bool special ; /// TODO: it would be ptr to semantic here
static std : : shared_ptr < ASTIdentifier > createSpecial ( const String & name_ )
{
auto ret = std : : make_shared < ASTIdentifier > ( name_ ) ;
ret - > special = true ;
return ret ;
}
2019-01-14 18:15:04 +00:00
2019-01-15 12:28:17 +00:00
void setSpecial ( ) { special = true ; }
2019-01-14 18:15:04 +00:00
friend void setIdentifierSpecial ( ASTPtr & ) ;
friend std : : optional < String > getColumnIdentifierName ( const ASTIdentifier & node ) ;
friend std : : optional < String > getColumnIdentifierName ( const ASTPtr & ast ) ;
friend std : : optional < String > getTableIdentifierName ( const ASTIdentifier & node ) ;
friend std : : optional < String > getTableIdentifierName ( const ASTPtr & ast ) ;
2019-01-15 12:28:17 +00:00
friend ASTPtr createTableIdentifier ( const String & database_name , const String & table_name ) ;
2010-06-24 19:12:10 +00:00
} ;
2019-01-14 18:15:04 +00:00
/// ASTIdentifier Helpers: hide casts and semantic.
2019-01-15 12:28:17 +00:00
ASTPtr createTableIdentifier ( const String & database_name , const String & table_name ) ;
2019-01-14 18:15:04 +00:00
bool isIdentifier ( const IAST * const ast ) ;
inline bool isIdentifier ( const ASTPtr & ast ) { return isIdentifier ( ast . get ( ) ) ; }
std : : optional < String > getIdentifierName ( const IAST * const ast ) ;
inline std : : optional < String > getIdentifierName ( const ASTPtr & ast ) { return getIdentifierName ( ast . get ( ) ) ; }
bool getIdentifierName ( const ASTPtr & ast , String & name ) ;
/// @returns name for column identifiers
std : : optional < String > getColumnIdentifierName ( const ASTIdentifier & node ) ;
std : : optional < String > getColumnIdentifierName ( const ASTPtr & ast ) ;
/// @returns name for 'not a column' identifiers
std : : optional < String > getTableIdentifierName ( const ASTIdentifier & node ) ;
std : : optional < String > getTableIdentifierName ( const ASTPtr & ast ) ;
void setIdentifierSpecial ( ASTPtr & ast ) ;
2019-01-16 17:26:14 +00:00
void addIdentifierQualifier ( ASTIdentifier & identifier , const String & database , const String & table , const String & alias ) ;
bool doesIdentifierBelongTo ( const ASTIdentifier & identifier , const String & table_or_alias ) ;
bool doesIdentifierBelongTo ( const ASTIdentifier & identifier , const String & database , const String & table ) ;
2019-01-14 18:15:04 +00:00
2010-06-24 19:12:10 +00:00
}