Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
4d532d9e
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4d532d9e
编写于
1月 03, 2019
作者:
D
Dmitriy Dubson and Nikhil Pawar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GP: Add Format Custom to External Table DDL generation
上级
e51a49aa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
2 deletion
+36
-2
plugins/org.jkiss.dbeaver.ext.greenplum/src/org/jkiss/dbeaver/ext/greenplum/model/GreenplumExternalTable.java
...s/dbeaver/ext/greenplum/model/GreenplumExternalTable.java
+13
-2
plugins/org.jkiss.dbeaver.ext.greenplum/tests/org/jkiss/dbeaver/ext/greenplum/model/GreenplumExternalTableTest.java
...eaver/ext/greenplum/model/GreenplumExternalTableTest.java
+23
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.greenplum/src/org/jkiss/dbeaver/ext/greenplum/model/GreenplumExternalTable.java
浏览文件 @
4d532d9e
...
@@ -35,7 +35,8 @@ import java.util.stream.Collectors;
...
@@ -35,7 +35,8 @@ import java.util.stream.Collectors;
public
class
GreenplumExternalTable
extends
PostgreTableRegular
{
public
class
GreenplumExternalTable
extends
PostgreTableRegular
{
public
enum
FormatType
{
public
enum
FormatType
{
c
(
"CSV"
),
c
(
"CSV"
),
t
(
"TEXT"
);
t
(
"TEXT"
),
b
(
"CUSTOM"
);
private
String
formatType
;
private
String
formatType
;
...
@@ -148,7 +149,8 @@ public class GreenplumExternalTable extends PostgreTableRegular {
...
@@ -148,7 +149,8 @@ public class GreenplumExternalTable extends PostgreTableRegular {
ddlBuilder
.
append
(
"\n) "
+
determineExecutionLocation
()
+
"\n"
);
ddlBuilder
.
append
(
"\n) "
+
determineExecutionLocation
()
+
"\n"
);
}
}
ddlBuilder
.
append
(
"FORMAT '"
+
this
.
getFormatType
().
getValue
()
+
"' ( "
+
this
.
getFormatOptions
()
+
" )"
);
ddlBuilder
.
append
(
"FORMAT '"
+
this
.
getFormatType
().
getValue
()
+
"' ( "
+
generateFormatOptions
(
this
.
getFormatType
(),
this
.
getFormatOptions
())
+
" )"
);
if
(
this
.
getEncoding
()
!=
null
&&
this
.
getEncoding
().
length
()
>
0
)
{
if
(
this
.
getEncoding
()
!=
null
&&
this
.
getEncoding
().
length
()
>
0
)
{
ddlBuilder
.
append
(
"\nENCODING '"
+
this
.
getEncoding
()
+
"'"
);
ddlBuilder
.
append
(
"\nENCODING '"
+
this
.
getEncoding
()
+
"'"
);
...
@@ -161,6 +163,15 @@ public class GreenplumExternalTable extends PostgreTableRegular {
...
@@ -161,6 +163,15 @@ public class GreenplumExternalTable extends PostgreTableRegular {
return
ddlBuilder
.
toString
();
return
ddlBuilder
.
toString
();
}
}
private
String
generateFormatOptions
(
FormatType
formatType
,
String
formatOptions
)
{
if
(
formatType
.
equals
(
FormatType
.
b
)){
String
[]
formatSpecTokens
=
formatOptions
.
split
(
" "
);
String
formatterSpec
=
formatSpecTokens
.
length
>=
2
?
formatSpecTokens
[
1
]
:
""
;
return
"FORMATTER="
+
formatterSpec
;
}
return
formatOptions
;
}
private
String
determineExecutionLocation
()
{
private
String
determineExecutionLocation
()
{
if
(
this
.
getExecLocation
()
!=
null
&&
this
.
getExecLocation
().
equalsIgnoreCase
(
"MASTER_ONLY"
))
{
if
(
this
.
getExecLocation
()
!=
null
&&
this
.
getExecLocation
().
equalsIgnoreCase
(
"MASTER_ONLY"
))
{
return
"ON MASTER"
;
return
"ON MASTER"
;
...
...
plugins/org.jkiss.dbeaver.ext.greenplum/tests/org/jkiss/dbeaver/ext/greenplum/model/GreenplumExternalTableTest.java
浏览文件 @
4d532d9e
...
@@ -263,6 +263,29 @@ public class GreenplumExternalTableTest {
...
@@ -263,6 +263,29 @@ public class GreenplumExternalTableTest {
Assert
.
assertEquals
(
expectedDDL
,
table
.
generateDDL
(
monitor
));
Assert
.
assertEquals
(
expectedDDL
,
table
.
generateDDL
(
monitor
));
}
}
@Test
public
void
generateDDL_whenTableHasACustomFormatType_returnsDDLStringWithACustomFormat
()
throws
DBException
,
SQLException
{
PostgreTableColumn
mockPostgreTableColumn
=
mockDbColumn
(
"column1"
,
"int4"
,
1
);
List
<
PostgreTableColumn
>
tableColumns
=
Collections
.
singletonList
(
mockPostgreTableColumn
);
Mockito
.
when
(
mockResults
.
getString
(
"fmttype"
)).
thenReturn
(
"b"
);
Mockito
.
when
(
mockResults
.
getString
(
"fmtopts"
)).
thenReturn
(
"FORMATTER 'formatter_export_s'"
);
GreenplumExternalTable
table
=
new
GreenplumExternalTable
(
mockSchema
,
mockResults
);
addMockColumnsToTableCache
(
tableColumns
,
table
);
String
expectedDDL
=
"CREATE EXTERNAL TABLE sampleDatabase.sampleSchema.sampleTable (\n\tcolumn1 int4\n)\n"
+
"LOCATION (\n"
+
"\t'gpfdist://filehost:8081/*.txt'\n"
+
") ON ALL\n"
+
"FORMAT 'CUSTOM' ( FORMATTER='formatter_export_s' )\n"
+
"ENCODING 'UTF8'"
;
Assert
.
assertEquals
(
expectedDDL
,
table
.
generateDDL
(
monitor
));
}
private
PostgreTableColumn
mockDbColumn
(
String
columnName
,
String
columnType
,
int
ordinalPosition
)
{
private
PostgreTableColumn
mockDbColumn
(
String
columnName
,
String
columnType
,
int
ordinalPosition
)
{
PostgreTableColumn
mockPostgreTableColumn
=
Mockito
.
mock
(
PostgreTableColumn
.
class
);
PostgreTableColumn
mockPostgreTableColumn
=
Mockito
.
mock
(
PostgreTableColumn
.
class
);
Mockito
.
when
(
mockPostgreTableColumn
.
getName
()).
thenReturn
(
columnName
);
Mockito
.
when
(
mockPostgreTableColumn
.
getName
()).
thenReturn
(
columnName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录