Faceting in solr - rest

Good day friends
I am facing a problem as I require to match the following query in solr
SELECT entidad, municipio, count(*) as total,
sum(case when ip like '10.%' then 1 else 0 end) as internos,
sum(case when ip not like '10.%' then 1 else 0 end) as externos
FROM bitacora.actividad a
where sistema = 'RGNPMarcas'
AND fecha >= '2021/07/16' and fecha <= '2021/07/31'
AND parametros like 'PDF'
and parametros like 'EGV'
and entidad = '01'
GROUP BY entidad, municipio
ORDER BY entidad, municipio
I have been researching on Faceting in solr, I have come to make some counts like the following, but the truth is that I have no idea how to mitigate this situation.
My schema is the following:
<field name="tabla" type="string" indexed="true" stored="false" multiValued="false"/>
<field name="entidad" type="string" indexed="true" stored="true" default="" multiValued="false"/>
<field name="municipio" type="string" indexed="true" stored="true" default="" multiValued="false"/>
<field name="ip" type="text_general" indexed="true" stored="true" default="" multiValued="false"/>
<field name="fecha" type="pdate" indexed="true" stored="true" multiValued="false" default=""/>
<field name="parametros" type="text_general" indexed="true" stored="true" default="" multiValued="false"/>
<field name="total" type="pint" uninvertible="true" indexed="true" stored="true"/>
<field name="internos" type="pint" uninvertible="true" indexed="true" stored="true"/>
<field name="externos" type="pint" uninvertible="true" indexed="true" stored="true"/>
As you can see, I already have the base and the indexed fields, what I need is your experience on these issues of solr or that someone can guide me, please!

if you could have one field with the name "ip_type" and the content "Internos" or "Externos" depending on weather or not the ip starts with "10.", then your query will have as Filter Query all the conditions you wrote after "where" (for instance "sistema = 'RGNPMarcas'") and the facet pivot would have 3 fields: "entidad,municipio,ip_type".
Now, in order to obtain the "ip_type" column, you can either change the way you index data (alter the input), or you can use a pattern replace char filter factory (https://solr.apache.org/guide/7_1/charfilterfactories.html#solr-patternreplacecharfilterfactory)

Related

Insert new data using Liquibase, postgreSQL and sequence

How do I make an insert for PostgreSQL using Liquibase if my ids are sequential. I try with the following:
<changeSet author="rparente" id="service-1.1-2019-01-09-01">
<insert tableName="tenant">
<column name="id"defaultValueSequenceNext="hibernate_sequence"/>
<column name="description" value="Prueba"/>
<column name="name" value="antel"/>
<column name="service_id" value="antel"/>
</insert>
</changeSet>
and I try with
<changeSet author="rparente" id="service-1.1-2019-01-09-01">
<insert tableName="tenant">
<column name="id" value="nextval('hibernate_sequence')"/>
<column name="description" value="Prueba"/>
<column name="name" value="antel"/>
<column name="service_id" value="antel"/>
</insert>
</changeSet>
The error is:
ERROR: null value in column "id" violates not-null constraint
I found the solution to insert data in Postgres with sequence (no default) ids
<changeSet author="author_name" id="service-1.1-2019-01-09-01">
<insert tableName="tenant">
<column name="id" valueSequenceNext="name_sequence"/>
<column name="description" value="TEST"/>
<column name="name" value="test"/>
<column name="service_id" value="testl"/>
<column name="status" value="ACTIVE"/>
</insert>
</changeSet>
Check out the ColumnConfig doc. You should be able to set a valueComputed property and in it call the Postgres function:
<column name="id" valueComputed="nextval('hibernate_sequence')"/>
As for me, I have to create a sequence first and then use it.
<changeSet>
<createSequence sequenceName="runtime_name_seq" dataType="bigint" incrementBy="1" maxValue="10000" minValue="1" startValue="1"/>
</changeSet>
<changeSet>
<createTable tableName="runtime_name">
<column name="id" type="INTEGER" defaultValueComputed="nextval('runtime_name_seq')">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_runtime_name"/>
</column>
</createTable>
</changeSet>
This will create a SQL by Liquibase (v3.8.1 I am using)
CREATE TABLE public.runtime_name
(
index INTEGER DEFAULT nextval('runtime_name_seq') NOT NULL
)

Jasper CVC Component with Sub-Dataset

I'm working on CVC component in Jasper Studio. It is working fine with the "ReportMainDataset" but when I'm using the "Sub Dataset" it is not plotting.
Just wanted to know does CVC component works with "Sub Dataset" or not. If works, guide me how can I achieve this.
The tag for indicating the dataset is <cvData>
Example
subdataset
<subDataset name="Dataset1" uuid="03d50d7f-1b96-486a-ac64-7d2c6e440433">
<queryString>
<![CDATA[select count(*) t, shipcountry, shipcity from orders group by shipcountry, shipcity order by shipcountry, shipcity]]>
</queryString>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<field name="T" class="java.lang.Long"/>
<field name="SHIPCITY" class="java.lang.String"/>
</subDataset>
component
<cvc:customvisualization xmlns:cvc="http://www.jaspersoft.com/cvcomponent" xsi:schemaLocation="http://www.jaspersoft.com/cvcomponent http://www.jaspersoft.com/cvcomponent/component.xsd" evaluationTime="Report" onErrorType="Icon">
<cvc:itemProperty name="script" value="d3_zoomable_circle_packing.min.js"/>
<cvc:itemProperty name="css" value="d3_zoomable_circle_packing.css"/>
<cvc:cvData>
<dataset>
<datasetRun subDataset="Dataset1" uuid="bd23d50f-2149-4985-a0ac-883505172688">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<cvc:item>
<cvc:itemProperty name="category">
<valueExpression><![CDATA[$F{SHIPCOUNTRY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="subcategory">
<valueExpression><![CDATA[$F{SHIPCITY}]]></valueExpression>
</cvc:itemProperty>
<cvc:itemProperty name="value">
<valueExpression><![CDATA[$F{T}]]></valueExpression>
</cvc:itemProperty>
</cvc:item>
</cvc:cvData>
</cvc:customvisualization>
EDIT: As #dada67 comment it does not seem to work properly, I have also test it with sample d3_zoomable_cricle_packing.jrxml without success, this is the bug issue
The work around, create a subreport!

JasperReports - Passing an Array of Strings from Filter to Postgresql

I'm trying to use an multi value column as a filter and passing an array of string but I'm getting this error message:
org.postgresql.util.PSQLException: ERROR: column "ae" does not exist Position: 122
Here is part of my JRXML file:
<parameter name="status" class="java.util.Collection">
<defaultValueExpression><![CDATA[new ArrayList(Arrays.asList(new String[] {}))]]></defaultValueExpression>
</parameter>
<parameter name="status_query" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{status}.isEmpty()
? "null"
: "array" + $P{status}]]></defaultValueExpression>
</parameter>
<queryString language="SQL">
<![CDATA[select * from _reports.my_proc($P!{status})]]>
</queryString>
Someone has an idea how to solve it? Thanks in advance.

jasper report passing parameter from list index

I got a scenario where I need to pass jasper report parameter value from a list using index.
I have the following query executed in the jasper report, with the following parameters defined.
<parameter name="clientServiceIds" class="java.util.Collection"/>
<parameter name="trafficPeriod" class="java.util.Collection"/>
<parameter name="transactionType" class="java.util.Collection"/>
<parameter name="transactionStatus" class="java.util.Collection"/>
<parameter name="roamingPartners" class="java.util.Collection"/>
<parameter name="ages" class="java.util.Collection"/>
SELECT
CLIENT_CODE,
PARTNER_ORG,
PARTNER_CODE,
SERVICE_TYPE,
TP_ID,
TRAFFIC_PERIOD,
SETTLEMENT_TYPE,
SDR_NET,
TRAN_CURR_NET,
TRAN_CURRENCY_ID,
DUE_DATE,
TRANSACTION_TYPE,
STATUS,
NOTE_ID,
AGE
FROM vw_transaction_search
WHERE $X{IN, client_service_id, clientServiceIds}
AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
AND $X{IN, traffic_period, trafficPeriod}
AND $X{IN, transaction_type, transactionType}
AND $X{IN, status_id, transactionStatus}
AND AGE BETWEEN $P{param1} AND $P{param2}
Here ages is a list which I am passing to the report, which contains two values at index 0 and index 1. All parameters (paramValueMap) I am getting from an external system which i cannot modify,
JasperFillManager.fillReport(jasperReport, paramValueMap, connection);
so I am looking for a way to pass parameters param1 and param2 in my Jasper report SQL from my Collection ages, something like param1=ages.get(0) and param2=ages.get(1), so the SQL will be something like
...AND $X{IN, status_id, transactionStatus}
AGE BETWEEN $P{ages.get(0)} AND $P{ages.get(1)}
is there any way possible to achieve this?
I was able to crack this down by adding two additional parameters age1 & age2 and passing the value to the added parameters from the list here are the details.
<parameter name="trafficPeriod" class="java.util.Collection"/>
<parameter name="transactionType" class="java.util.Collection"/>
<parameter name="transactionStatus" class="java.util.Collection"/>
<parameter name="roamingPartners" class="java.util.Collection"/>
<parameter name="age" class="java.util.List" isForPrompting="false"/>
<parameter name="age1" class="java.lang.Integer" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{age}.get(0)]]></defaultValueExpression>
</parameter>
<parameter name="age2" class="java.lang.Integer" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{age}.get(1)]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
CLIENT_CODE,
PARTNER_ORG,
PARTNER_CODE,
SERVICE_TYPE,
TP_ID,
TRAFFIC_PERIOD,
SETTLEMENT_TYPE,
SDR_NET,
TRAN_CURR_NET,
TRAN_CURRENCY_ID,
DUE_DATE,
TRANSACTION_TYPE,
STATUS,
NOTE_ID,
AGE
FROM vw_transaction_search
WHERE $X{IN, client_service_id, clientServiceIds}
AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
AND $X{IN, traffic_period, trafficPeriod}
AND $X{IN, transaction_type, transactionType}
AND $X{IN, status_id, transactionStatus}
AND AGE BETWEEN $P{age1} AND $P{age2}
ORDER BY client_code,
partner_code,
traffic_period,
age]]>
</queryString>

Adding an entity key when no key is inferred from a view

I have a database view which joins across a number of tables in SQL Server 2005. It looks something like this:
SELECT
m1.MenuName AS menu_name, m2.MenuName AS sub_menu_name, p.ProductName, od.amount
FROM
dbo.tblMenus AS m1
FULL OUTER JOIN
dbo.tblMenus AS m2
FULL OUTER JOIN
dbo.tblProductsRelMenus AS pm ON m2.Id = pm.SubMenuId ON m1.Id = pm.MenuId
FULL OUTER JOIN
(SELECT
dbo.tblOrderDetails.ProductId, SUM(dbo.tblOrderDetails.Ammount) AS amount
FROM
dbo.tblOrderDetails
FULL OUTER JOIN
dbo.tblOrders AS o ON dbo.tblOrderDetails.OrderId = o.OrderId
WHERE (o.OrderDestroyed = 0)
GROUP BY dbo.tblOrderDetails.ProductId) AS od
RIGHT OUTER JOIN
dbo.tblProducts AS p ON od.ProductId = p.ProductId ON pm.ProductId = p.ProductId
When I try to create an ADO .Net entity data model it complains about not having a primary key in the SSDL secion. I then found this:
http://msdn.microsoft.com/en-us/library/dd163156.aspx
but I don't understand the part about a defining query. Surely I just want a column with unique numbers to define the key, or?
<EntityType Name="SoldItemsView">
<Key>
<PropertyRef Name="SoldItemsViewId" />
</Key>
<Property Name="SoldItemsView" Type="int" Nullable="false" />
<Property Name="menu_name" Type="nvarchar" MaxLength="100" />
<Property Name="sub_menu_name" Type="nvarchar" MaxLength="100" />
<Property Name="ProductName" Type="nvarchar" MaxLength="50" />
<Property Name="amount" Type="int" />
</EntityType>
But how do I populate this column with unique numbers?
Thanks,
Barry
You can use only columns from the view. To define an entity key you must select column (or set of columns) from your view which uniquely identifies record from the view.