【问题标题】:Apache Phoenix create view throws TableAlreadyExistExceptionApache Phoenix 创建视图抛出 TableAlreadyExistException
【发布时间】:2017-03-30 08:37:36
【问题描述】:

我使用 shell 在 Hbase 中创建了一个表,其中包含 2 个列族。我可以使用 Hbase 客户端 API 写入它。我正在使用 phoenix JDBC 驱动程序从中查询数据。我了解到 HBase 和 Phoenix 表之间没有一对一的映射。所以,我为我现有的表创建了一个视图,但是每当我运行我的代码时,我都会得到 ​​p>

org.apache.phoenix.schema.TableAlreadyExistsException: ERROR 1013 (42M04): Table already exists. tableName=test
at org.apache.phoenix.schema.MetaDataClient.createTableInternal(MetaDataClient.java:1911)
at org.apache.phoenix.schema.MetaDataClient.createTable(MetaDataClient.java:744)
at org.apache.phoenix.compile.CreateTableCompiler$2.execute(CreateTableCompiler.java:186)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:303)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:295)
at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:293)
at org.apache.phoenix.jdbc.PhoenixStatement.executeUpdate(PhoenixStatement.java:1236)
at com.lam.app.PhoenixClient.main(PhoenixClient.java:49)

我的客户端代码是这样的

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PhoenixClient
{

    public static void main(String[] args)
    {
        // Create variables
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        PreparedStatement ps = null;

        try
        {
            // Connect to the database
            connection = DriverManager.getConnection("jdbc:phoenix:zkserver:2181:/hbase-unsecure");

            // Create a JDBC statement
            statement = connection.createStatement();

            //HBase table schema - Table name : test, columnfamily 1 - data, ColumnFamily2 - context 
            // Execute our statements
            statement.executeUpdate("CREATE VIEW \"test\" (pk VARCHAR not null PRIMARY KEY, "
                    + "\"data\".\"mydata\" VARCHAR," + " \"context\".\"mycontext\" VARCHAR)");

            //connection.commit();

            // Query for table
            /*ps = connection
                .prepareStatement("select * from \"test\" WHERE \"mydata\" = \"names\"");
            rs = ps.executeQuery();
            System.out.println("Table Values");
            while (rs.next())
            {
                Integer myKey = rs.getInt(1);
                String myColumn = rs.getString(2);
                System.out.println("\tRow: " + myKey + " = " + myColumn);
            }*/

        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            if (ps != null)
            {
                try
                {
                    ps.close();
                }
                catch (Exception e)
                {
                }
            }
            if (rs != null)
            {
                try
                {
                    rs.close();
                }
                catch (Exception e)
                {
                }
            }
            if (statement != null)
            {
                try
                {
                    statement.close();
                }
                catch (Exception e)
                {
                }
            }
            if (connection != null)
            {
                try
                {
                    connection.close();
                }
                catch (Exception e)
                {
                }
            }
        }

    }
}

我可以使用 Hbase shell 扫描表并查看数据,并且我知道表名区分大小写(特别是 phoenix 将所有内容都设为大写),但不确定为什么我无法创建视图。请帮忙

【问题讨论】:

  • 正如错误所说,您已经在 Hbase 中有名为“test”的表。换个名字
  • @NirmalRam 我知道表“test”已经存在,因为我使用 Hbase shell 创建了它,但我想做的是使用 Phoenix 为它创建一个视图,以便我可以使用查询。
  • 也许您可以在创建视图之前尝试删除它?

标签: java hbase phoenix


【解决方案1】:

按照@rickmoritz 的建议,我在创建视图之前放弃了它,这很有效。

statement.executeUpdate("DROP VIEW \"test\"");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-23
    • 2020-08-06
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    相关资源
    最近更新 更多