THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||
---|---|---|---|---|
| ||||
/** * Cache this table to builtin table service or the specified customized table service. * * This method provides a hint to Flink that the current table maybe reused later so a * cache should be created to avoid regenerating this table. * * The following code snippet gives an example of how this method could be used. * * {{{ * val t = tEnv.fromCollection(data).as('country, 'color, 'count) * * val t1 = t.filter('count < 100).cache() * // t1 is cached after it is computed for the first time. * val x = t1.executeInsert("Sink1"t1.execute().print() * * // When t1 is used again to compute t2, it may not be re-computed. * val t2 = t1.groupBy('country).select('country, 'count.sum as 'sum) * val res2 = t2.executeInsert("Sink2"execute().print() * * // Similarly when t1 is used again to compute t3, it may not be re-computed. * val t3 = t1.groupBy('color).select('color, 'count.avg as 'avg) * val res3 = t3.executeInsert("Sink3"t3.execute().print() * * }}} * * @note Flink optimizer may decide to not use the cache if doing that will accelerate the * processing, or if the cache is no longer available for reasons such as the cache has * been invalidated. * @note The table cache could be create lazily. That means the cache may be created at * the first time when the cached table is computed. * @note The table cache will be cleared when the user program exits. * @note This method is only supported in batch table and it is treated as No-Op for stream table * * @return the current table with a cache hint. The original table reference is not modified * by the execution of this method. If this method is called on a table with cache * hint, the same table object will return. */ def cache(): Table /** * Manually invalidate the cache of this table to release the physical resources. Users are * not required to invoke this method to release physical resource unless they want to. The * table caches are cleared when user program exits. * * @note After invalidated, the cache may be re-created if this table is used again. */ def invalidateCache(): Unit |
...
Code Block | ||
---|---|---|
| ||
TableEnvironment tEnv = ... Table t1 = ... Table t2 = t1.cache() ... tEnv.execute() // t1 is cached. Table t3 = t1.select(...) // cache will NOT be used. Table t4 = t2.select(...) // cache will be used. ... // The following two lines of code are equivalent t1.invalidateCache() // cache will be released t2.invalidateCache() // cache will be released ... t1.execute().print() // cache will NOT be recreated t2.execute().print() // cache will be recreated |
...