簡體   English   中英

hbase-如何在不刪除表的情況下更改表結構

[英]hbase - how to change tables structure without drop tables

我使用grails-1.3.2和gorm-hbase-0.2.4插件。

有時我需要更改表結構(添加新表或列)。 我已經創建了Car表:

class Car{
    static belongsTo = [user:User]

    String color
    String model
    //.....

    static constraints = {
    }
}

但是當我想創建汽車對象時:

def create = {
        Car car = new Car()
        car.properties = params
        car.save(flush: true)        
 }

我有以下異常:

ERROR gorm.SavePersistentMethod  - APP_CAR
org.apache.hadoop.hbase.TableNotFoundException: APP_CAR

在我使用create-drop運行應用程序之后,一切正常都開始工作..但是我無法在每次更改后刪除所有數據,我認為插件必須完成所有更新

因此,我在changind表結構繼續運行應用程序而沒有放置表之后尋找某種方式。

如果有人知道解決方案,請幫忙。

Grails不會自動更新您的表,如果它會自動刪除生產中的列怎么辦? 也許那不是您想要的。

有一個數據庫遷移插件可以做到這一點,這是一個很好的鏈接來解釋它。 請注意,您需要使用grails prod而不是直接在鏈接中使用grails prod ,否則它將僅在開發模式下運行。 該鏈接在其命令中未顯示prod。

官方鏈接在這里 ,關於此的spring來源博客在這里

數據庫遷移插件將不起作用,因為它僅適用於休眠狀態。 您需要在插件源中進行一些更改。 HBasePluginSupport.grovy

static doWithApplicationContext = {ApplicationContext applicationContext ->
    LOG.debug("Closure HBasePluginSupport.doWithApplicationContext{} invoked with arg $applicationContext")

    assert !PluginManagerHolder.getPluginManager().hasGrailsPlugin("hibernate"),"hibernate plug-in conflicts with gorm-hbase plug-in"

    // Read data source configuration, setting defaults as required
    def dataSource = application.config.dataSource
    // TODO write tests for this <--- Even maybe figure out if this is ever invoked
    if (!dataSource) dataSource = new HBaseDefaults()

    def dbCreate = dataSource?.dbCreate
    if (!dbCreate) dbCreate = "create-drop"
    LOG.debug("Data Source configured with dbCreate set to $dbCreate")

    // TODO Complete dbCreate related processing
    if (dbCreate?.toUpperCase()?.equals("CREATE-DROP")) {
        def createIndexedTables = dataSource?.indexed
        LOG.debug ("Flag createIndexedTables set to $createIndexedTables")
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")

        tableManager.createSequenceTable()
        tableManager.createReferenceTable()

        application.domainClasses.each {domainClass ->
            LOG.debug("Adding table for Domain Class $domainClass")
            tableManager.createDomainTable(domainClass, createIndexedTables)
        }

        LOG.debug("List of all store found :")
        tableManager.getTableNames().each {tn ->
            LOG.debug("- $tn")
        }
    } else if (dbCreate?.toUpperCase()?.equals("UPDATE")) {
        def createIndexedTables = dataSource?.indexed
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")
        def existingTables = tableManager.getTableNames();

        application.domainClasses.each {domainClass ->
            LOG.debug("Domain Class $domainClass")
            def tableDesc = new HTableDescriptor(HBaseNameUtils.getDomainTableName(domainClass))
            if (!existingTables.contains(tableDesc.getNameAsString())) {
                tableManager.createDomainTable(domainClass, createIndexedTables)
                LOG.debug("Adding table for Domain Class $domainClass")
            }
        }
    }

    application.domainClasses.each {domainClass ->
        LOG.debug("Adding dbms related methods to Domain Class $domainClass")
        def domainClassManager = new HBaseDomainClassManager()
        domainClassManager.createQueryMethods(domainClass)
        domainClassManager.createPersistenceMethods(domainClass)
        domainClassManager.addLazyLoadingSupport(domainClass)
        domainClassManager.addDynamicFinders(domainClass)
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM