Hadoop Hive:创建具有动态位置的外部表(Hadoop Hive: create external table with dynamic location)
我正在尝试创建一个指向S3输出文件的Hive外部表。
文件名应反映当前日期(它始终是新文件)。我试过这个:
CREATE EXTERNAL TABLE s3_export (...) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION concat('s3://BlobStore/Exports/Daily_', from_unixtime(unix_STRING(),'yyyy-MM-dd'));
但是我收到一个错误:
FAILED:解析错误:第3行:第9行不匹配的输入'concat'期望表位置规范中'LOCATION'附近的StringLiteral有没有办法动态指定表位置?
I am trying to create a Hive external table that points to an S3 output file.
The file name should reflect the current date (it is always a new file).I tried this:
CREATE EXTERNAL TABLE s3_export (...) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION concat('s3://BlobStore/Exports/Daily_', from_unixtime(unix_STRING(),'yyyy-MM-dd'));
but I get an error:
FAILED: Parse Error: line 3:9 mismatched input 'concat' expecting StringLiteral near 'LOCATION' in table location specificationis there any way to dynamically specify table location?
原文:https://stackoverflow.com/questions/17525789
最满意答案
一种方法是将缩小的数组转储到第二个数组,然后将第二个数组转储到您的范围
下面的代码生成一个3600行乘16列(即A:P)的变量数组,数据被转储到数组中以获取样本数据(注意您已将此数组作为Var) ,然后使用变量作为标记来减少将数组转换为第二个数组,然后将第二个数组写入范围。
已更新,以匹配您的确切数据位置。 在你的情况下你已经有Var1(你的Var),所以你只需要从
lngStop = 350
开始的代码的第二部分并使我的代码Var1
引用Var
Sub TestME() Dim Var1 Dim Var2 Dim lngCnt As Long Dim lngCnt2 As Long Dim lngCnt3 As Long Dim lngCnt4 As Long Dim lngStop As Long Var1 = Sheet1.Range([a1], [p3600]).Value2 For lngCnt = 1 To UBound(Var1, 1) For lngCnt2 = 1 To 16 Var1(lngCnt, lngCnt2) = "I am row " & lngCnt & " column " & lngCnt2 Next lngCnt2 Next lngCnt lngStop = 350 ReDim Var2(1 To UBound(Var1, 1) - lngStop + 1, 1 To UBound(Var1, 2)) For lngCnt3 = lngStop To UBound(Var1, 1) For lngCnt4 = 1 To UBound(Var1, 2) Var2(lngCnt3 - lngStop + 1, lngCnt4) = Var1(lngCnt3, lngCnt4) Next lngCnt4 Next lngCnt3 Sheet1.[a3444].Resize(UBound(Var2, 1), UBound(Var2, 2)).Value2 = Var2 End Sub
One way is to dump the reduced array to a second array, then the second array to your range
The code below makes a variant array with 3600 rows by 16 columns (ie A:P), data is dumped into the array for sample data (note you already have this array as Var), then a variable is used as a marker to reduce the array to a second array, the second array is then written to the range.
Updated to match your exact data locations. In your case you have Var1 already (your Var), so you just need the second portion of the code that starts at
lngStop = 350
and make my codeVar1
referencesVar
Sub TestME() Dim Var1 Dim Var2 Dim lngCnt As Long Dim lngCnt2 As Long Dim lngCnt3 As Long Dim lngCnt4 As Long Dim lngStop As Long Var1 = Sheet1.Range([a1], [p3600]).Value2 For lngCnt = 1 To UBound(Var1, 1) For lngCnt2 = 1 To 16 Var1(lngCnt, lngCnt2) = "I am row " & lngCnt & " column " & lngCnt2 Next lngCnt2 Next lngCnt lngStop = 350 ReDim Var2(1 To UBound(Var1, 1) - lngStop + 1, 1 To UBound(Var1, 2)) For lngCnt3 = lngStop To UBound(Var1, 1) For lngCnt4 = 1 To UBound(Var1, 2) Var2(lngCnt3 - lngStop + 1, lngCnt4) = Var1(lngCnt3, lngCnt4) Next lngCnt4 Next lngCnt3 Sheet1.[a3444].Resize(UBound(Var2, 1), UBound(Var2, 2)).Value2 = Var2 End Sub
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
Range对象的Sort()和Autofilter()方法的组合应该非常快: Option Explicit Sub TestVariant() Dim iCat As Long With Worksheets("Sheet1") With .Range("AD1", .Cells(.Rows.COUNT, 1).End(xlUp)) .Sort key1:=Range("A1"), order1:=xlAscending, Header:=xlY ...
-
如何找出变量中使用范围的大小,忽略空的范围(How to find out the size of used range in the variant ignoring the empty ones)[2023-03-01]
根据jonsca的评论,如果您知道有多少条记录已被写入或操作(2020),那么您可以在最后从2721记录大小切割数组 这里的诀窍是,您无法重新映射数组的第一维并保留现有数据,因此我们需要三个阶段的解决方法 创建第二个数组,其中水平大小等于数组1的垂直大小,垂直大小等于数组1的水平大小(而不是2720行4列,我们使用4行2720列) 在代码末尾将2720到2020的列删除并保留书面记录 将第二个数组转储回Excel,但使用Transpose将2020行中的4行转换为2020行* 4列 下面的示例(转储到第二张 ... -
一种方法是将缩小的数组转储到第二个数组,然后将第二个数组转储到您的范围 下面的代码生成一个3600行乘16列(即A:P)的变量数组,数据被转储到数组中以获取样本数据(注意您已将此数组作为Var) ,然后使用变量作为标记来减少将数组转换为第二个数组,然后将第二个数组写入范围。 已更新,以匹配您的确切数据位置。 在你的情况下你已经有Var1(你的Var),所以你只需要从lngStop = 350开始的代码的第二部分并使我的代码Var1引用Var Sub TestME() Dim Var1 Dim Var2 Di ...
-
啊,我错过了Set关键字: Sub test() Dim rng As Range Dim not_rng As Variant Set rng = Sheets("Test").Range("A1:B2") Debug.Print TypeName(rng) Set not_rng = rng Debug.Print TypeName(not_rng) End Sub 现在打印 Range Range 这更有意义。 Ah, I was missing t ...
-
如果您计划使用varray来查看每行中的单元格以决定是否应该删除该行,则应该向后遍历varray,就像在单元格范围内执行for循环一样。 由于您从第1行开始,变量i将始终等于元素所在的行号,因此您可以使用它来删除正确的行。 下面是一个示例(比您尝试的更简单),它将删除A列和B列中的单元格相同的每一行。 Sub test() Dim varray As Variant varray = Range("A1:B11").Value For i = UBound(varray, 1) To 1 Step -1 ...
-
这是你想要的吗? Sub Sample() Dim ws As Worksheet, wsSumry As Worksheet Dim startRow As Long, StartCol As Long Dim i As Long, j As Long Dim ar(1 To 4, 1 To 4) As Variant '~~> Start row and start column startRow = 2: StartCol = 2 '~~> ...
-
排序变种?(sorting a variant?)[2023-01-07]
尼科, 而不是在变体中实现排序例程,您应该使用Excel的本机排序。 如果您正在努力处理当前文件(我建议您首先尝试使用手动计算对当前数据进行排序),那么解决方法将是 从您当前的文件中派生您的变体 将变量转储到新工作簿(关闭当前文件是一个选项) 运行排序,然后创建新的排序变量数组,或更新现有的变量数组 将已排序的变量数组转储回原始文件(或根据需要进一步操作) Niko, Rather than implement a sort routine inside the variant you should use ... -
以下是我解决这个问题的方法: Private Function getData(ByVal query As String, ByVal conStr As String) As Object Dim adapter As New Data.OleDb.OleDbDataAdapter(query, conStr) Dim dataSet As New Data.DataSet adapter.Fill(dataSet) Dim dataTable As Data.DataT ...
-
AFAIK,您无法创建一个Range对象,该对象不以某种方式引用工作簿的工作表位置。 它可以是动态的东西,比如Named = OFFSET()函数,但它必须绑定到某个地方的工作表。 为什么不改变插值函数? 按原样保留Linterp签名,但将其作为在数组上插值的函数的包装器。 像这样的东西: Function Linterp(rng As Range, x As Double) As Double ' R is a two-column range containing known x, known y ' ...