本文整理了Java中org.apache.spark.sql.hive.HiveContext.sql()
方法的一些代码示例,展示了HiveContext.sql()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HiveContext.sql()
方法的具体详情如下:
包路径:org.apache.spark.sql.hive.HiveContext
类名称:HiveContext
方法名:sql
暂无
代码示例来源:origin: Impetus/Kundera
@Override
public void registerTable(EntityMetadata m, SparkClient sparkClient)
{
sparkClient.sqlContext.sql("use " + m.getSchema());
}
代码示例来源:origin: Impetus/Kundera
/**
* Gets the data frame.
*
* @param query
* the query
* @param m
* the m
* @param kunderaQuery
* the kundera query
* @return the data frame
*/
public DataFrame getDataFrame(String query, EntityMetadata m, KunderaQuery kunderaQuery)
{
PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata().getPersistenceUnitMetadata(
persistenceUnit);
String clientName = puMetadata.getProperty(DATA_CLIENT).toLowerCase();
SparkDataClient dataClient = SparkDataClientFactory.getDataClient(clientName);
if (registeredTables.get(m.getTableName()) == null || !registeredTables.get(m.getTableName()))
{
dataClient.registerTable(m, this);
registeredTables.put(m.getTableName(), true);
}
// at this level temp table or table should be ready
DataFrame dataFrame = sqlContext.sql(query);
return dataFrame;
}
代码示例来源:origin: Impetus/Kundera
@Override
public boolean persist(List listEntity, EntityMetadata m, SparkClient sparkClient)
{
try
{
Seq s = scala.collection.JavaConversions.asScalaBuffer(listEntity).toList();
ClassTag tag = scala.reflect.ClassTag$.MODULE$.apply(m.getEntityClazz());
JavaRDD personRDD = sparkClient.sparkContext.parallelize(s, 1, tag).toJavaRDD();
DataFrame df = sparkClient.sqlContext.createDataFrame(personRDD, m.getEntityClazz());
sparkClient.sqlContext.sql("use " + m.getSchema());
if (logger.isDebugEnabled())
{
logger.info("Below are the registered table with hive context: ");
sparkClient.sqlContext.sql("show tables").show();
}
df.write().insertInto(m.getTableName());
return true;
}
catch (Exception e)
{
throw new KunderaException("Cannot persist object(s)", e);
}
}
代码示例来源:origin: org.apache.camel/camel-spark
@Override
public void process(Exchange exchange) throws Exception {
HiveContext hiveContext = resolveHiveContext();
String sql = exchange.getIn().getBody(String.class);
Dataset<Row> resultFrame = hiveContext.sql(sql);
exchange.getIn().setBody(getEndpoint().isCollect() ? resultFrame.collectAsList() : resultFrame.count());
}
代码示例来源:origin: ddf-project/DDF
@Override
public SqlResult sql(String command, Integer maxRows, DataSourceDescriptor dataSource) throws DDFException {
// TODO: handle other dataSources and dataFormats
DataFrame rdd = this.getHiveContext().sql(command);
Schema schema = SparkUtils.schemaFromDataFrame(rdd);
String[] strResult = SparkUtils.df2txt(rdd, "\t");
return new SqlResult(schema,Arrays.asList(strResult));
}
代码示例来源:origin: Quetzal-RDF/quetzal
public static void main( String[] args )
{
// SparkConf conf = new SparkConf().setAppName("App-mt").setMaster("local[2]");
// SparkConf conf = new SparkConf().setAppName("App-mt").setMaster("spark://Kavithas-MBP.home:7077");
SparkConf conf = new SparkConf().setAppName("App-mt").setMaster("spark://kavithas-mbp.watson.ibm.com:7077");
JavaSparkContext sc = new JavaSparkContext(conf);
HiveContext sqlContext = new HiveContext(sc.sc());
DataFrame urls = sqlContext.read().json("/tmp/urls.json");
urls.registerTempTable("urls");
DataFrame temp = sqlContext.sql("select * from urls");
temp.show();
sqlContext.sql("add jar /tmp/quetzal.jar");
sqlContext.sql("create temporary function webservice as 'com.ibm.research.rdf.store.utilities.WebServiceGetUDTF'");
DataFrame drugs = sqlContext.sql("select webservice(\"drug,id,action\", \"url\", \"\", \"GET\", \"xs=http://www.w3.org/2001/XMLSchema\", \"//row\",\"drug\",\"./drug\","
+ " \"<string>\", \"id\", \"./id\",\"<string>\", \"action\", \"./action\", \"<string>\", url) as (drug, drug_typ, id, id_typ, action, action_typ) from urls");
drugs.show();
System.out.println("Num rows:" + drugs.count());
}
代码示例来源:origin: ddf-project/DDF
@Override
public SqlTypedResult sqlTyped(String command, Integer maxRows, DataSourceDescriptor dataSource) throws DDFException {
DataFrame rdd = ((SparkDDFManager) this.getManager()).getHiveContext().sql(command);
Schema schema = SparkUtils.schemaFromDataFrame(rdd);
int columnSize = schema.getNumColumns();
Row[] rddRows = rdd.collect();
List<List<SqlTypedCell>> sqlTypedResult = new ArrayList<List<SqlTypedCell>>();
// Scan every cell and add the type information.
for (int rowIdx = 0; rowIdx < rddRows.length; ++rowIdx) {
List<SqlTypedCell> row = new ArrayList<SqlTypedCell>();
for (int colIdx = 0; colIdx < columnSize; ++ colIdx) {
// TODO: Optimize by reducing getType().
row.add(new SqlTypedCell(schema.getColumn(colIdx).getType(), rddRows[rowIdx].get(colIdx).toString()));
}
sqlTypedResult.add(row);
}
return new SqlTypedResult(schema, sqlTypedResult);
}
代码示例来源:origin: ddf-project/DDF
for(Column column: categoricalColumns) {
String sqlCmd = String.format("select distinct(%s) from %s where %s is not null", column.getName(), this.getDDF().getTableName(), column.getName());
DataFrame sqlresult = sqlContext.sql(sqlCmd);
Row[] rows = sqlresult.collect();
List<String> values = new ArrayList<>();
DataFrame sqlResult = sqlContext.sql(sql);
Row[] rows = sqlResult.collect();
Row result = rows[0];
代码示例来源:origin: ddf-project/DDF
@Override
public DDF sql2ddf(String command, Schema schema, DataSourceDescriptor dataSource, DataFormat dataFormat) throws DDFException {
// TableRDD tableRdd = null;
// RDD<Row> rddRow = null;
DataFrame rdd = this.getHiveContext().sql(command);
if (schema == null) schema = SchemaHandler.getSchemaFromDataFrame(rdd);
DDF ddf = this.getManager().newDDF(this.getManager(), rdd, new Class<?>[]
{DataFrame.class}, null, schema);
ddf.getRepresentationHandler().cache(false);
ddf.getRepresentationHandler().get(new Class<?>[]{RDD.class, Row.class});
return ddf;
}
内容来源于网络,如有侵权,请联系作者删除!