Solr data-config multiple statements in query - java

Solr example:
<entity name="item" query="select * from item">
If I want to do a query like this:
<entity name="item" query="BEGIN some_package.some_function(x,y); END;
select * from item">
how can I achieve this in Solr? In the event it isn't obvious what I want to do, I want to run some_function(x,y) right before I execute the standard select * query against my table. I have achieved similar functionality in JDBC

Related

Is it possible to use Aggregate functions in MyBatis

I am a newbie to MyBatis. As per my knowledge every column is mapped to a property value while retrieving data from the database. So is it possible to use aggregate functions using MyBatis. To what property we will map the results? I have searched it everywhere But can't find any details about the usage of aggregate functions with MyBatis. If anyone can help, please.
Every column of the result set is mapped to a property. Therefore, it's just a matter of producing a SQL statement that does that.
For example:
<resultMap id="regionProfit" type="app.RegionProfitVO">
<result property="region" column="region" />
<result property="cnt" column="cnt" />
<result property="profit" column="profit" />
</resultMap>
<select id="getRegionProfit" resultMap="regionProfit">
select
region,
count(sales) as cnt,
sum(revenue) - sum(expenses) as profit
from sales
group by region
</select>
Now, in the Java code you could do something like:
List<RegionProfitVO> rp = sqlSession.selectList("getRegionProfit");
If you don't want to create another POJO, you can always retrieve the result as a list of java.util.Map<String, Object> but use resultType="hashmap" in mapper.xml file for that select query

how to call a stored procedure from a block Select a MyBatis 2.3.5

my select block is
<select id="getItemsCount" resultClass="java.math.BigDecimal" parameterClass="com.item.SimlpeListFilter">
SELECT COUNT(1) FROM T_SYSTEM.T_ITEM_LIST
<include refid="itemListFilter"/>
</select>
in itemListFilte have procedure calls, adding there {call anyProcedure} is not appropriate. Filter dynamic forms. May contain procedures. Which does not cause a query

How to properly outline an Apache Solr document?

What is the difference between delta import and full import in ApacheSolr?
What are all the naming conventions to be followed while writing deltaImportQuery and deltaQuery ( ID, TXT_ID etc), any references or tutorial explaining in detail about differences/relations between deltaImportQuery and deltaQuery, Like what it is and what it does etc, How to write deltaImportQuery and deltaQuery ?
How to configure multiple entities in one document, Suppose if there are three tables in database like T1, T2, T3, Then in schema.xml how to configure this, issue with only one <uniquekey>somename</uniquekey> been considered for each schema.xml file?
How to parse BLOB type input from mysql, following convert ( column_name using utf8 ) as alias_name solves this but what is the right convention ,some other methods are also available like using TikaEntityProcessor/ writing custom BLOBTRANSFORMERS etc ?
Just like ORM any concepts explaining how to denormalize and outline an Apache Solr document , Any showcase project including all use cases and features ?
How to configure entities like this in data-config.xml?
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/solrdemo" user="root" password="123" batchSize='1' />
<document name="user">
<entity name ="user1" query = "SELECT * FROM user1">
<field column='id' name='id1' />
</entity>
<entity name ="user2" query = "SELECT * FROM user2">
<field column='id' name='id2' />
</entity>
<entity name ="user3" query = "SELECT * FROM user3">
<field column='id' name='id3' />
</entity>
</document>
</dataConfig>
When the above kind of configuration is done then in schema.xml which id should be configured into <uniquekey></uniquekey> ?
The result of above configuration is
Indexing completed. Added/Updated: 2,866 documents. Deleted 0 documents. (Duration: 03s)
Indexing is successfully completed but 0 documents added / updated , How to resolve this issue ?
Overall any references available for proper conventions and configurations to work with Apache Solr?

Solr query only returns Id's

I have wanting to import data from a table and index it using solr..
I am using solr-tomcat admin panel.
But whenever I query it returns to me only the id's and value.
I have also tried adding FIELDS to fl , but that also does not help.
here is my data-config.xml file:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/{DB_NAME}"
user="{DB_USER}"
password="{DB_PASSS}"
/>
<document>
<entity name="id" query="select s3_location,file_name from video">
<field column="s3_location" name="s3_location"/>
<field column="file_name" name="file_name"/>
</entity>
</document>
</dataConfig>
Is there any way to get the above s3_location and file_name fields also.
You need to specify the actual field names in the fl parameter or use * to indicate all fields. Also, please note that the fields must have been defined with stored=true in your schema.xml file for them to be returned/visible during a query.
fl=id,s3_location,file_name
fl=*
Are you sure you are importing the data at all? If you start with empty index, do you get anything?
The reason I ask is because you are not mapping the id field explicitly. Now, I believe there is implicit mapping of the fields by Jdbc data source based on names, but relying on it is risky when you are just starting.
Otherwise, like Paige said, make sure you defined those fields in your schema and that they are actually stored.

How do you handle sql mapping for multiple tables in ibatis and java

I am trying to use Ibatis with GWT and I have this scenario, I have databases tables Airport, Terminals and Flights. An airport can have different terminals. A terminal can have one Airport and many flights. And a flight can have one terminal. So the table structure looks like this.
Airport
-id
-name
-terminal_id
Terminals
-id
-name
-flight_id
Flights
-id
-airline
-terminal_id
My select statement looks like this
SELECT airport.name AS Airport,
terminals.name AS Terminal,
flights.airline,
FROM airport,
terminals,
flights
WHERE airport.terminal_id = terminals.id
AND terminals.flight_id = flights.id;
What will the sql maps look like to get this result. Where I'm getting confused is the result set is a combination of tables and so the result set isn't a model object of either of the three tables.
Create a custom value object(vo) to suit your need.
<sqlMap namespace="Arrival">
<resultMap id="Arrival" class="com.flight.vo.Arrival">
<result property="airport" column="Airport" />
<result property="terminal" column="Terminal" />
<result property="airline" column="airline"/>
</resultMap>
<select id="retrieveAllArrivals" resultMap="Arrival.Arrival" >
select airport.name as Airport, terminals.name as Terminal, flights.airline
FROM airport, terminals, flights
WHERE airport.terminal_id = terminals.id
AND terminals.flight_id = flights.id
</select>
</sqlMap>

Categories