OpenJPA not taking full column name in query - jpql

I am using OpenJPA and doing the mapping using orm.xml. For certain cases where my column name length is more than some number of characters then jpql while generating sql query generates the column name as only upto some number of characters.
If i have a mapping as below
<entity name="OneOffSystemTemplateVariableValue" class="financing.tools.docgen.models.OneOffSystemTemplateVariableValue">
<table name="modification_variable_values"/>
<attribute-override name="id">
<column name="modification_variable_values_id"/>
</attribute-override>
.....
</attributes>
</entity>
When i run a simple query on OneOffSystemTemplateVariableValue, it generated my query as below
SELECT t0.**MODIFICATION_VARIABLE_VALUES_I**, t0.create_timestamp, t0.create_id, t0.last_update_timestamp, t0.last_update_id, t0.modification_object_id, t0.variable_name, t0.variable_value FROM Administrator.modification_variable_values t0 WHERE t0.one_off_template_id = ?
Here for MODIFICATION_VARIABLE_VALUES_ID column if i change column name to MOD_VARIABLE_VALUES_ID then my query works good.
So sql generated is not taking full column name length.
I have not set the maxColumnNameLength anywhere in my application.
Can you tell me how can i set the value of column name length so that i may not face this problem.

If you are using MySQL, you would set the following property in your persistence.xml file.
openjpa.jdbc.DBDictionary=mysql(maxColumnNameLength=256)
For other databases refer to the OpenJPA user manual. I'd also be interested in knowing which database you're using so we might be able to fix this max column issue.

Related

Solr count mismatch between facet and filter query

I am running solr 7.7.2 and I am trying to apply facet on a particular field
"display-classification_en_string_mv" (type="string" indexed="true" stored="false" multiValued="true")
The problem is when I try to apply facets on this field, with
acet=true&facet.field={!ex%3Dfkdisplay-classification}display-classification_en_string_mv&facet.mincount=1&facet.limit=10&facet.sort=count,
The actual facet count I get for a variant of this field "maxi dress" is 100 as shown below.
Now when I try to add a filterquery (fq) like this
fq={!tag%3Dfkdisplay-classification}+display-classification_en_string_mv:"Maxi+Dress"
the actual count increases to 101.
One thing to note is I am using a collapse query to group documents having same value in a field of type="string" indexed="true" stored="true".
This count mismatch happens only when the collapse query is applied, and without the collapsing in place, the count remains same in both cases.
Please let me know if I am missing something or any error in implementation which might lead to this.
Apparently, the collapse query selects one of the documents in the group as a leader and selects it for counting facets, and in one of the group, the leader which was getting selected didn't have the field considered for facets.

GCP Data Catalog - search columns containing a dot in the column name

Take the public github dataset as an example
SELECT
*
FROM
`bigquery-public-data.github_repos.commits`
LIMIT
2
There are column names like
difference.old_mode
via search:
column:difference.old_mode
will show no results
So, in this case the period isn't actually the column name, its an indication that you're dealing with a complex type (there's a record/struct column of name difference, and within that exists a column named old_mode.
Per search reference there's no special syntax for complex schemas documented.
A suggestion might be to leverage a logical AND operator like column:(difference,old_mode). It's not as precise as specifying the column relationship, but it should return the results you're interested in receiving.

Is there a workaround for the maximum length of an ODBCConnection.CommandText string in VBA?

I have a VBA script that generates a query string for a SAP HANA ODBC Connection in Excel. The query is determined by user inputs and can vary greatly in length. The query itself uses many versions of a similar query appended to one another using UNION ALL syntax.
The script sometimes throws a runtime error when trying to refresh. From my research, it has become clear that the reason for this is that the CommandText string exceeds a maximum allowed length of 32,767 (https://ask.sqlservercentral.com/questions/50819/too-long-sql-in-excel-vba.html).
I wondered whether there is a workaround for this, other than using a stored procedure (I am not against this if there is a way to create a stored procedure at runtime then execute it, but I cannot use a predefined stored procedure as my query is always different hence the need for VBA to create it)
Some more info about the dynamic query in VBA:
Column names, as well as parameters, are created dynamically and can be different every time
The query uses groups of lists of product numbers to generate an IN statement for each product group, then sums the sales for those products under the name of the group. These are then all UNION'd together to create one table with grouped records
Example of user input:
Example of resulting query:
WITH SOME_CTE (SOME_FIELDS) AS
(SELECT SOME_STUFF
FROM SOME_TABLE
WHERE SOME_STUFF_IS_GOING_ON)
SELECT GEND "Gender", 'Attribute 1' "Attribute", SUM(UNITS) "Units", SUM(VAL) "Value", SUM(MARGIN) "Margin"
FROM SOME_CTE
WHERE PRODUCT IN ('12345', '23456', '34567', '45678')
GROUP BY GEND
UNION ALL
SELECT GEND, 'Attribute 2' ATTR_NAME, SUM(UNITS), SUM(VAL), SUM(MARGIN)
FROM SOME_CTE
WHERE PRODUCT IN ('01234', '02345', '03456', '03567')
GROUP BY GEND
ORDER BY "Gender", "Attribute"
...and so on.
As you can see, with 2 attribute groups containing 4 products each there is no problem, but when we get to about 30 with several hundred each, it could be too long.
Note: I have tried things like shortening field references in the repeated parts of the query string to 1 character etc. which helps but does not solve the problem.
Any help would be greatly appreciated.
One workaround is to send multiple queries. Since you are using union all, you could execute every time single select statement, i.e.
create table in (for example) master database (don't create temporary tables! as they will be dropped after every query) - but before that, make sure you create new table, so delete old one if exists (also drop the table after you are done with it). Now every single select statement you'll change to insert statement, which will insert records to your so-called temporary table.
This way, you'll avoid lengthy queries, you'll just send single insert .. into.. select statements.
At the end, to get all results, you just need simple select query. After getting this data, you should drop that table, as it's no longer needed.

CRM 2011 Performing FetchXML group by on custom option set value

I want to be able to perform a FetchXML request that sums a value while grouping on a field that is a custom option set but I don't get the expected results.
All that is returned is the summed up values, not the related custom option set value that it relates to so I have no idea what the returned values relate to.
This is the fetchXML request which appears to be correct:
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='opportunity'>
<attribute name='estimatedvalue' alias='opportunity_sum' aggregate='sum' />
<attribute name='koo_opportunitytype' alias='koo_opportunitytype' groupby='true' />
</entity>
</fetch>
Each value that is returned only has 1 attribute...the opportunity_sum value.
If I group by say, customer id, then the returned values are summed up correctly and a reference is returned to the related customer for each summed value which is what I would expect.
Is it not possible to group by a custom option set value? This seems to work fine with standard system option set values such as status code.
I have verified that your fetch xml works just fine as long as the data is clean. If all of your koo_opportunitytype values for opportunities are null, it will not return an attribute for them. I'm assuming that you're only getting one entity returned? Also if any estimated value is null for a group, the sum will not be returned either. This means you'll probably want to add a filter to exclude null values from your sum.

How to sort by date in SOLR?

I want to sort the results and scores returning from SOLR search,how I can get scores based on date like below:
Suppose for keywords "football"
12-10-2012 - 3.2
13-10-2012 - 1.5
My solr date filed lis like below:
<field name="published_date" datetimeformat="dd-MM-yyyy" type="date" indexed="true" stored="true"/>
I checked this docs but couldn't find that.
Thanks.
You can pass the sort parameter in the URL
e.g. sort=published_date desc for documents by published date in descending order.
If you want to sort by score and date you can use sort=score desc, published_date desc
taken from the wiki
Although not technically a Syntax difference, please note that if you use
the Solr "DateField" type, any queries on those fields (typically range queries)
should use either the Complete ISO 8601 Date syntax that field supports,
or the DateMath Syntax to get
relative dates. Examples:
timestamp:[* TO NOW]
createdate:[1976-03-06T23:59:59.999Z TO *]
createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]
pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]
createdate:[1976-03-06T23:59:59.999Z TO 1976-03-06T23:59:59.999Z+1YEAR]
createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z]
NOTE:TO must be uppercase, or Solr will report a 'Range Goop' error.
combine that with this and the job is done :) it's pretty easy, it just requires some tries in the beginning
a little edit: this method allows you to retrieve values based on a date range and apply a score boost to them according to their values. apparently you were asking help on how to retrieve sort on base score and date, so my answer isn't the 100% correct one

Resources