当前位置: 首页>>代码示例>>Java>>正文


Java CreateTable类代码示例

本文整理汇总了Java中com.facebook.presto.sql.tree.CreateTable的典型用法代码示例。如果您正苦于以下问题:Java CreateTable类的具体用法?Java CreateTable怎么用?Java CreateTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CreateTable类属于com.facebook.presto.sql.tree包,在下文中一共展示了CreateTable类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
/**
 * Creates a table based on a select on another type and inserts the data (currently not possible to
 * perform this action 'WITH NO DATA'.
 * @param sql
 * @param createAsSelect
 * @param index
 * @return the number of rows inserted
 * @throws SQLException
 */
public int execute(String sql, CreateTableAsSelect createAsSelect, String index) throws SQLException {
	if(!createAsSelect.isWithData()) throw new SQLException("Not yet possible to create table as select without data (create emtpy table, "
			+ "insert data and delete it will have the same effect");
	// first create the index
	SqlParser parser = new SqlParser();
	int queryIdx = sql.toLowerCase().indexOf(" as ");
	try{
		String createSql = sql.substring(0, queryIdx)+" (_id String)" ;
		CreateTable create = (CreateTable)parser.createStatement(createSql);
		this.execute(createSql, create, index);
		
	}catch(SQLException sqle) {
		throw sqle;
	}catch(Exception e){
		throw new SQLException("Unable to create table due to: "+e.getMessage(), e);
	}
	
	// secondly add the documents from the query
	String insertSql = "INSERT INTO "+createAsSelect.getName().toString()+" "+sql.substring(queryIdx+4);
	Insert insert = (Insert)parser.createStatement(insertSql);
	int res = this.execute(insertSql, insert, index);
	this.statement.getConnection().getTypeMap(); // trigger a reload of the table&column set for the connection
	return res;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:34,代码来源:ESUpdateState.java

示例2: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
protected Void visitCreateTable(CreateTable node, Integer indent)
{
    builder.append("CREATE TABLE ");
    if (node.isNotExists()) {
        builder.append("IF NOT EXISTS ");
    }
    builder.append(node.getName())
            .append(" (");

    Joiner.on(", ").appendTo(builder, transform(node.getElements(),
            element -> element.getName() + " " + element.getType()));

    builder.append(")");

    if (!node.getProperties().isEmpty()) {
        builder.append(" WITH (");
        Joiner.on(", ").appendTo(builder, transform(node.getProperties().entrySet(),
                entry -> entry.getKey() + " = " + formatExpression(entry.getValue())));
        builder.append(")");
    }

    return null;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:25,代码来源:SqlFormatter.java

示例3: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
protected Void visitCreateTable(CreateTable node, Integer indent)
{
    builder.append("CREATE TABLE ")
        .append(genDottedName(node.getName()))
        .append(" AS ");

    process(node.getQuery(), indent);

    builder.append("WITH DATA");

    return null;
}
 
开发者ID:ajoabraham,项目名称:hue,代码行数:14,代码来源:VeroTeradataSqlFormatter.java

示例4: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
protected Void visitCreateTable(CreateTable node, Integer indent)
{
    builder.append("CREATE TABLE ")
        .append(genDottedName(node.getName()))
        .append(" AS ");

    process(node.getQuery(), indent);

    builder.append("WITH NO DATA");

    return null;
}
 
开发者ID:ajoabraham,项目名称:hue,代码行数:14,代码来源:VeroDerbySqlFormatter.java

示例5: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
protected Void visitCreateTable(CreateTable node, Integer indent)
{
    builder.append("CREATE TABLE ")
        .append(genDottedName(node.getName()))
        .append(" AS ");

    process(node.getQuery(), indent);
    
    builder.append("WITH DATA");

    return null;
}
 
开发者ID:ajoabraham,项目名称:hue,代码行数:14,代码来源:VeroAccessSqlFormatter.java

示例6: executeUpdate

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
public int executeUpdate(String sql) throws SQLException {
	//System.out.println("QUERY: ["+sql+"]");
	sql = sql.replaceAll("\r", " ").replaceAll("\n", " ").trim();
	// custom stuff to support UPDATE statements since Presto does not parse it
	if(sql.toLowerCase().startsWith("update")){
		return updateState.execute(sql);
	}
	
	com.facebook.presto.sql.tree.Statement statement = parser.createStatement(sql);
	if(statement instanceof Query) throw new SQLException("A regular query cannot be executed as an Update");
	if(statement instanceof Insert){
		//if(connection.getSchema() == null) throw new SQLException("No active index set for this driver. Pleas specify an active index or alias by executing 'USE <index/alias>' first");
		return updateState.execute(sql, (Insert)statement, connection.getSchema());
	}else if(statement instanceof Delete){
		if(connection.getSchema() == null) throw new SQLException("No active index set for this driver. Pleas specify an active index or alias by executing 'USE <index/alias>' first");
		return updateState.execute(sql, (Delete)statement, connection.getSchema());
	}else if(statement instanceof CreateTable){
		return updateState.execute(sql, (CreateTable)statement, connection.getSchema());
	}else if(statement instanceof CreateTableAsSelect){
		return updateState.execute(sql, (CreateTableAsSelect)statement, connection.getSchema());
	}else if(statement instanceof CreateView){
		return updateState.execute(sql, (CreateView)statement, connection.getSchema());
	}else if(statement instanceof Use){
		connection.setSchema( ((Use)statement).getSchema());
		//connection.getTypeMap(); // updates the type mappings found in properties
		return 0;
	}else if(statement instanceof DropTable){
		return updateState.execute(sql, (DropTable)statement);
	}else if(statement instanceof DropView){
		return updateState.execute(sql, (DropView)statement);
	}throw new SQLFeatureNotSupportedException("Unable to parse provided update sql");
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:34,代码来源:ESStatement.java

示例7: executeBulk

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
/**
 * Executes the {@link BulkRequest} being hold by this state.
 * @return an integer indicator for each executed request: Statement.SUCCESS_NO_INFO for success, 
 * else Statement.EXECUTE_FAILED)
 */
public int[] executeBulk(){
	int[] result = new int[bulkList.size()];
	SqlParser parser = new SqlParser();
	for(int i=0; i<bulkList.size(); i++) try{
		String sql = bulkList.get(i);
		com.facebook.presto.sql.tree.Statement st = parser.createStatement(sql);
		if(st instanceof DropTable){
			this.execute(sql, (DropTable)st);
		}else if(st instanceof DropView){
			this.execute(sql, (DropView)st);
		}else if(st instanceof CreateTable){
			this.execute(sql, (CreateTable)st, this.statement.getConnection().getSchema());
		}else if(st instanceof CreateTableAsSelect){
			this.execute(sql, (CreateTableAsSelect)st, this.statement.getConnection().getSchema());
		}else if(st instanceof CreateView){
			this.execute(sql, (CreateView)st, this.statement.getConnection().getSchema());
		}else if(st instanceof Delete){
			this.execute(sql, (Delete)st, this.statement.getConnection().getSchema());
		}else  if(st instanceof Insert){
			this.execute(sql, (Insert)st, this.statement.getConnection().getSchema());
		}
		result[i]= Statement.SUCCESS_NO_INFO;
	}catch (Exception e){
		result[i] = Statement.EXECUTE_FAILED;
	}
	this.clearBulk();
	return result;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:34,代码来源:ESUpdateState.java

示例8: execute

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
public CompletableFuture<?> execute(CreateTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    checkArgument(!statement.getElements().isEmpty(), "no columns for table");

    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (tableHandle.isPresent()) {
        if (!statement.isNotExists()) {
            throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Table '%s' already exists", tableName);
        }
        return completedFuture(null);
    }

    List<ColumnMetadata> columns = new ArrayList<>();
    for (TableElement element : statement.getElements()) {
        Type type = metadata.getType(parseTypeSignature(element.getType()));
        if ((type == null) || type.equals(UNKNOWN)) {
            throw new SemanticException(TYPE_MISMATCH, element, "Unknown type for column '%s' ", element.getName());
        }
        columns.add(new ColumnMetadata(element.getName(), type, false));
    }

    accessControl.checkCanCreateTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    Map<String, Object> properties = metadata.getTablePropertyManager().getTableProperties(
            tableName.getCatalogName(),
            statement.getProperties(),
            session,
            metadata);

    TableMetadata tableMetadata = new TableMetadata(
            tableName.getCatalogName(),
            new ConnectorTableMetadata(tableName.asSchemaTableName(), columns, properties, session.getUser(), false));

    metadata.createTable(session, tableName.getCatalogName(), tableMetadata);

    return completedFuture(null);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:41,代码来源:CreateTableTask.java

示例9: testCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Test
public void testCreateTable()
        throws Exception
{
    assertStatement("CREATE TABLE foo (a VARCHAR, b BIGINT)",
            new CreateTable(QualifiedName.of("foo"),
                    ImmutableList.of(new TableElement("a", "VARCHAR"), new TableElement("b", "BIGINT")),
                    false,
                    ImmutableMap.of()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)",
            new CreateTable(QualifiedName.of("bar"),
                    ImmutableList.of(new TableElement("c", "TIMESTAMP")),
                    true,
                    ImmutableMap.of()));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:16,代码来源:TestSqlParser.java

示例10: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
protected CatalogSchemaContext visitCreateTable(CreateTable node, CatalogSchemaContext context)
{
    references.add(qualifiedNameToTable(node.getName(), context));
    visitCreateTable(node, context);

    return context;
}
 
开发者ID:airbnb,项目名称:airpal,代码行数:9,代码来源:InputReferenceExtractor.java

示例11: explain

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
public String explain(CreateTable statement)
{
    return "CREATE TABLE " + statement.getName();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:6,代码来源:CreateTableTask.java

示例12: visitCreateTable

import com.facebook.presto.sql.tree.CreateTable; //导入依赖的package包/类
@Override
public Node visitCreateTable(SqlBaseParser.CreateTableContext context)
{
    return new CreateTable(getLocation(context), getQualifiedName(context.qualifiedName()), visit(context.tableElement(), TableElement.class), context.EXISTS() != null, processTableProperties(context.tableProperties()));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:6,代码来源:AstBuilder.java


注:本文中的com.facebook.presto.sql.tree.CreateTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。