Github user gatorsmile commented on the pull request: https://github.com/apache/spark/pull/12134#issuecomment-204861588 In SQL Context, the plan is wrong if we use CREATE VIEW AS SELECT. We need to ```scala sql("CREATE VIEW testView AS SELECT * FROM jt").explain(true) ``` ``` == Parsed Logical Plan == 'Project [*] +- 'UnresolvedRelation `jt`, None == Analyzed Logical Plan == intType: int, stringType: string, dateType: date, timestampType: timestamp, doubleType: double, bigintType: bigint, tinyintType: tinyint, decimalType: decimal(10,0), fixedDecimalType: decimal(5,1), binaryType: binary, booleanType: boolean, smallIntType: smallint, floatType: float, mapType: map<string,string>, arrayType: array<string>, structType: struct<f1:string,f2:int> Project [intType#155,stringType#156,dateType#157,timestampType#158,doubleType#159,bigintType#160L,tinyintType#161,decimalType#162,fixedDecimalType#163,binaryType#164,booleanType#165,smallIntType#166,floatType#167,mapType#168,arrayType#169,structType#170] +- SubqueryAlias jt +- Relation[intType#155,stringType#156,dateType#157,timestampType#158,doubleType#159,bigintType#160L,tinyintType#161,decimalType#162,fixedDecimalType#163,binaryType#164,booleanType#165,smallIntType#166,floatType#167,mapType#168,arrayType#169,structType#170] SimpleDDLScan(1,10,test1) == Optimized Logical Plan == Relation[intType#155,stringType#156,dateType#157,timestampType#158,doubleType#159,bigintType#160L,tinyintType#161,decimalType#162,fixedDecimalType#163,binaryType#164,booleanType#165,smallIntType#166,floatType#167,mapType#168,arrayType#169,structType#170] SimpleDDLScan(1,10,test1) == Physical Plan == WholeStageCodegen : +- Scan SimpleDDLScan(1,10,test1)[intType#155,stringType#156,dateType#157,timestampType#158,doubleType#159,bigintType#160L,tinyintType#161,decimalType#162,fixedDecimalType#163,binaryType#164,booleanType#165,smallIntType#166,floatType#167,mapType#168,arrayType#169,structType#170] ``` The expected one should be like ``` == Parsed Logical Plan == 'CreateViewAsSelect CatalogTable(`testView`,CatalogTableType(VIRTUAL_VIEW),CatalogStorageFormat(None,None,None,None,Map()),List(),List(),List(),0,1459654853237,1459654853237,Map(),Some(SELECT * FROM jt),Some(SELECT * FROM jt)), false, false, CREATE VIEW testView AS SELECT * FROM jt +- 'Project [*] +- 'UnresolvedRelation `jt`, None == Analyzed Logical Plan == CreateViewAsSelect CatalogTable(`default`.`testview`,CatalogTableType(VIRTUAL_VIEW),CatalogStorageFormat(None,None,None,None,Map()),List(),List(),List(),0,1459654853237,1459654853237,Map(),Some(SELECT * FROM jt),Some(SELECT * FROM jt)), Project [intType#0,stringType#1,dateType#2,timestampType#3,doubleType#4,bigintType#5L,tinyintType#6,decimalType#7,fixedDecimalType#8,binaryType#9,booleanType#10,smallIntType#11,floatType#12,mapType#13,arrayType#14,structType#15], false, false == Optimized Logical Plan == CreateViewAsSelect CatalogTable(`default`.`testview`,CatalogTableType(VIRTUAL_VIEW),CatalogStorageFormat(None,None,None,None,Map()),List(),List(),List(),0,1459654853237,1459654853237,Map(),Some(SELECT * FROM jt),Some(SELECT * FROM jt)), Project [intType#0,stringType#1,dateType#2,timestampType#3,doubleType#4,bigintType#5L,tinyintType#6,decimalType#7,fixedDecimalType#8,binaryType#9,booleanType#10,smallIntType#11,floatType#12,mapType#13,arrayType#14,structType#15], false, false == Physical Plan == ExecutedCommand CreateViewAsSelect CatalogTable(`default`.`testview`,CatalogTableType(VIRTUAL_VIEW),CatalogStorageFormat(None,None,None,None,Map()),List(),List(),List(),0,1459654853237,1459654853237,Map(),Some(SELECT * FROM jt),Some(SELECT * FROM jt)), Project [intType#0,stringType#1,dateType#2,timestampType#3,doubleType#4,bigintType#5L,tinyintType#6,decimalType#7,fixedDecimalType#8,binaryType#9,booleanType#10,smallIntType#11,floatType#12,mapType#13,arrayType#14,structType#15], false, false ``` We must disable it in the parser to make sure CREATE VIEW is allowed only in Hive Context.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org