SparkSQL08_SQLCommand_02_DescribeTable
2015-10-16 11:12
148 查看
1. 执行如下SQL命令
2.执行结果
3.物理计划执行结果
4.DescribeCommand的代码
sc.textFile("file:///D:\\myprojects\\SparkSQLPerf\\data\\students.txt") .map(x => x.split(" ")) .map(x => (Student3(x(0), x(1), x(3), x(2).toInt))).toDF().registerTempTable("TBL_STUDENT")
val df = sqlContext.sql("describe TBL_STUDENT") df.show()
2.执行结果
+--------+---------+-------+ |col_name|data_type|comment| +--------+---------+-------+ | id| string| | | name| string| | | classId| string| | | age| int| | +--------+---------+-------+
3.物理计划执行结果
== Parsed Logical Plan == nodeName: <DescribeCommand>, argString:< ('nodeName: <UnresolvedRelation>, argString:< [TBL_STUDENT], None>), false> == Analyzed Logical Plan == col_name: string, data_type: string, comment: string nodeName: <DescribeCommand>, argString:< ('nodeName: <UnresolvedRelation>, argString:< [TBL_STUDENT], None>), false> == Optimized Logical Plan == nodeName: <DescribeCommand>, argString:< ('nodeName: <UnresolvedRelation>, argString:< [TBL_STUDENT], None>), false> == Not Prepared Physical Plan == nodeName: <ExecutedCommand>, argString:< nodeName: <DescribeCommand>, argString:< (Scan PhysicalRDD[AttributeReference:id#0,AttributeReference:name#1,AttributeReference:classId#2,AttributeReference:age#3]), [AttributeReference:col_name#6,AttributeReference:data_type#7,AttributeReference:comment#8], false> > == Prepared Physical Plan == nodeName: <ExecutedCommand>, argString:< nodeName: <DescribeCommand>, argString:< (Scan PhysicalRDD[AttributeReference:id#0,AttributeReference:name#1,AttributeReference:classId#2,AttributeReference:age#3]), [AttributeReference:col_name#6,AttributeReference:data_type#7,AttributeReference:comment#8], false> >
4.DescribeCommand的代码
case class DescribeCommand( child: SparkPlan, override val output: Seq[Attribute], isExtended: Boolean) extends RunnableCommand { override def run(sqlContext: SQLContext): Seq[Row] = { val a = child.schema val b = a.fields b .map { field => val cmtKey = "comment" val m = field.metadata val comment = if (m.contains(cmtKey)) m.getString(cmtKey) else "" //列名,列的类型,列的注释 Row(field.name, field.dataType.simpleString, comment) } } }
相关文章推荐
- JDBC与MySql:手把手教你JDBC入门
- mysql 数据库分区
- MS-SQL Server字符串处理函数大全
- oracle中escape的使用
- linux下安装配置Memcache和PHP环境
- 查询优化【SQL优化】
- 查询优化【SQL优化】
- servlet中访问mysql无法包含中文的解决
- redis 如何批量获取数据
- mysql语句总结
- 几种常用DB驱动和DB连接串,方便大家用各种程序,连接数据库。
- mysql远程访问
- mysql优化基础
- mysql使用
- PowerDesigner连接oracle数据库时出现由于系统错误 1114 (oracle in oradb11g_home1)指定驱动程序无法加载 sqlstate=IM003
- sql语句练习50题
- sql server2005版本中,len函数计算了字符串末尾的空格
- memcached的总结和分布式一致性hash
- oracle 11gR2 RAC 连接实例时遇到ora-12537,求指点
- 分组后分组合计以及总计SQL语句--收集未整理