It seems that doctrine sets parameters in a wrong order. I have the following parameter array:
$params = array(
1 => array(1, 2, 3, 4, 5, 6),
2 => array(150, 12, 130),
3 => 'CALLED',
4 => array('ND', 'PF', 'OS'),
5 => '2015-07-02 00:00:00',
6 => '2015-07-05 00:00:00'
);
And i have the following query
$query = $this->getEntityManager()->createQuery('
SELECT c FROM Customers\Entity\Customer c
WHERE c.customer_categories_id IN(?1)
AND c.countries_id IN(?2)
AND c.state = ?3
AND c.potential_diamonds IN(?4)
AND c.last_call NOT BETWEEN ?5 AND ?6
');
$query->setParameters($params);
$result = $query->getResult();
And this is the final query:
SELECT c0_.id AS id_0, c0_.company AS company_1, c0_.vat_number AS vat_number_2, c0_.first_name AS first_name_3, c0_.last_name AS last_name_4, c0_.phone AS phone_5, c0_.phone2 AS phone2_6, c0_.mobile AS mobile_7, c0_.email AS email_8, c0_.email2 AS email2_9, c0_.fax AS fax_10, c0_.address AS address_11, c0_.address2 AS address2_12, c0_.postal_code AS postal_code_13, c0_.town AS town_14, c0_.province AS province_15, c0_.countries_id AS countries_id_16, c0_.customer_titles_id AS customer_titles_id_17, c0_.customer_categories_id AS customer_categories_id_18, c0_.present_list AS present_list_19, c0_.vip_list AS vip_list_20, c0_.previous_sold AS previous_sold_21, c0_.previous_bought AS previous_bought_22, c0_.opening_hours AS opening_hours_23, c0_.main_office AS main_office_24, c0_.newsletter AS newsletter_25, c0_.website AS website_26, c0_.`state` AS state_27, c0_.potential_diamonds AS potential_diamonds_28, c0_.remarks AS remarks_29, c0_.date_created AS date_created_30, c0_.date_changed AS date_changed_31, c0_.last_call AS last_call_32, c0_.customer_languages_id AS customer_languages_id_33, c0_.display_state AS display_state_34, c0_.longitude AS longitude_35, c0_.latitude AS latitude_36 FROM customers c0_ WHERE c0_.customer_categories_id IN ('ND', '2015-07-05 00:00:00', 'CALLED', 130, 130, 'CALLED') AND c0_.countries_id IN ('ND', '2015-07-05 00:00:00', '2015-07-02 00:00:00') AND c0_.`state` = 'PF' AND c0_.potential_diamonds IN ('2015-07-02 00:00:00', 'OS', 'PF') AND c0_.last_call NOT BETWEEN 'OS' AND 12
if we look in the WHERE part of the query than we see that the parameters are completely flipped. This is very strange. does anyone have an explanation for this or have the same problem? There is not much to find on google.
Thanks in advance
Related
Does anybody know how to performe a window function in apache beam (dataflow)?
Example:
Ex
ID Sector Country Income
1 Liam US 16133
2 Noah BR 10184
3 Oliver ITA 11119
4 Elijah FRA 13256
5 William GER 7722
6 James AUS 9786
7 Benjamin ARG 1451
8 Lucas FRA 4541
9 Henry US 9111
10 Alexander ITA 13002
11 Olivia ENG 5143
12 Emma US 18076
13 Ava MEX 15930
14 Charlotte ENG 18247
15 Sophia BR 9578
16 Amelia FRA 10813
17 Isabella FRA 7575
18 Mia GER 14875
19 Evelyn AUS 19749
20 Harper ITA 19642
Questions:
How to create another column with the running sum of the Income ordered by ID?
How to create another column with the Rank of the people who earns the most
Thank You
Bruno
Consider below approach. I have tried my best to make sure that the Pado fns are associative and commutative. Which means this should not break when run parallel on multiple workers. Let me know if you find this breaking over DataflowRunner
import apache_beam as beam
from apache_beam.transforms.core import DoFn
class cum_sum(DoFn):
def process(self, element,lkp_data,accum_sum):
for lkp_id_income in lkp_data:
if element['ID'] >= lkp_id_income[0]:
accum_sum += lkp_id_income[1]
element.update({'cumulative_sum':accum_sum})
yield element
class rank_it(DoFn):
def process(self, element, lkp_data,counter):
for lkp_id_cumsum in lkp_data:
if lkp_id_cumsum['cumulative_sum'] < element['cumulative_sum']:
counter += 1
element.update({'rank':counter})
yield element
with beam.Pipeline() as p:
data = (
p
| 'create'>>beam.Create(
[
{
'ID':4,
'Sector':'Liam',
'Country':'US',
'Income':1400
},
{
'ID':2,
'Sector':'piam',
'Country':'IS',
'Income':1200
},
{
'ID':1,
'Sector':'Oiam',
'Country':'PS',
'Income':1300
},
{
'ID':3,
'Sector':'Uiam',
'Country':'OS',
'Income':1800
}
]
)
)
ids_income = (
data
| 'get_ids_income'>>beam.Map(lambda element: (element['ID'], element['Income']))
)
with_cumulative_sum = (
data
| 'cumulative_sum'>>beam.ParDo(cum_sum(),lkp_data = beam.pvalue.AsIter(ids_income),accum_sum = 0)
)
with_ranking =(
with_cumulative_sum
| 'ranking'>>beam.ParDo(rank_it(),lkp_data = beam.pvalue.AsIter(with_cumulative_sum),counter = 1)
| 'print'>>beam.Map(print)
)
Output
{'ID': 4, 'Sector': 'Liam', 'Country': 'US', 'Income': 1400, 'cumulative_sum': 5700, 'rank': 4}
{'ID': 2, 'Sector': 'piam', 'Country': 'IS', 'Income': 1200, 'cumulative_sum': 2500, 'rank': 2}
{'ID': 1, 'Sector': 'Oiam', 'Country': 'PS', 'Income': 1300, 'cumulative_sum': 1300, 'rank': 1}
{'ID': 3, 'Sector': 'Uiam', 'Country': 'OS', 'Income': 1800, 'cumulative_sum': 4300, 'rank': 3}
Windowing in Apache Beam subdivide your unbounded PCollection in smaller bounded chunk to apply some computation (group by, sum, avg,..).
Unbounded PCollection comes from streaming processing and windows are based on timestamp (you can create sliding window of 5 minutes for instance). In your example, you haven't timestamps, and sounds like a bounded PCollection (a batch).
Technically you can simulate timestamp by preprocessing the elements and adding a dummy time indicator. But in your case, a simple groupby, or a sort is enough to achieve what you want.
I am trying to extract where clause from SQL query.
Multiple conditions in where clause should be in form array. Please help me.
Sample Input String:
select * from table where col1=1 and (col2 between 1 and 10 or col2 between 190 and 200) and col2 is not null
Output Expected:
Array("col1=1", "(col2 between 1 and 10 or col2 between 190 and 200)", "col2 is not null")
Thanks in advance.
EDIT:
My question here is like... I would like to split all the conditions as separate items... let's say my query is like
select * from table where col1=1 and (col2 between 1 and 10 or col2 between 190 and 200) and col2 is not null
The output I'm expecting is like
List("col1=1", "col2 between 1 and 10", "col2 between 190 and 200", "col2 is not null")
The thing is the query may have multiple levels of conditions like
select * from table where col1=1 and (col2 =2 or(col3 between 1 and 10 or col3 is between 190 and 200)) and col4='xyz'
in output each condition should be a separate item
List("col1=1","col2=2", "col3 between 1 and 10", "col3 between 190 and 200", "col4='xyz'")
I wouldn't use Regex for this. Here's an alternative way to extract your conditions based on Catalyst's Logical Plan :
val plan = df.queryExecution.logical
val predicates: Seq[Expression] = plan.children.collect{case f: Filter =>
f.condition.productIterator.flatMap{
case And(l,r) => Seq(l,r)
case o:Predicate => Seq(o)
}
}.toList.flatten
println(predicates)
Output :
List(('col1 = 1), ((('col2 >= 1) && ('col2 <= 10)) || (('col2 >= 190) && ('col2 <= 200))), isnotnull('col2))
Here the predicates are still Expressions and hold information (tree representation).
EDIT :
As asked in comment, here's a String (user friendly I hope) representation of the predicates :)
val plan = df.queryExecution.logical
val predicates: Seq[Expression] = plan.children.collect{case f: Filter =>
f.condition.productIterator.flatMap{
case o:Predicate => Seq(o)
}
}.toList.flatten
def stringifyExpressions(expression: Expression): Seq[String] = {
expression match{
case And(l,r) => (l,r) match {
case (gte: GreaterThanOrEqual,lte: LessThanOrEqual) => Seq(s"""${gte.left.toString} between ${gte.right.toString} and ${lte.right.toString}""")
case (_,_) => Seq(l,r).flatMap(stringifyExpressions)
}
case Or(l,r) => Seq(Seq(l,r).flatMap(stringifyExpressions).mkString("(",") OR (", ")"))
case eq: EqualTo => Seq(s"${eq.left.toString} = ${eq.right.toString}")
case inn: IsNotNull => Seq(s"${inn.child.toString} is not null")
case p: Predicate => Seq(p.toString)
}
}
val stringRepresentation = predicates.flatMap{stringifyExpressions}
println(stringRepresentation)
New Output :
List('col1 = 1, ('col2 between 1 and 10) OR ('col2 between 190 and 200), 'col2 is not null)
You can keep playing with the recursive stringifyExpressions method if you want to customize the output.
EDIT 2 : In response to your own edit :
You can change the Or / EqualTo cases to the following
def stringifyExpressions(expression: Expression): Seq[String] = {
expression match{
case And(l,r) => (l,r) match {
case (gte: GreaterThanOrEqual,lte: LessThanOrEqual) => Seq(s"""${gte.left.toString} between ${gte.right.toString} and ${lte.right.toString}""")
case (_,_) => Seq(l,r).flatMap(stringifyExpressions)
}
case Or(l,r) => Seq(l,r).flatMap(stringifyExpressions)
case EqualTo(l,r) =>
val prettyLeft = if(l.resolved && l.dataType == StringType) s"'${l.toString}'" else l.toString
val prettyRight = if(r.resolved && r.dataType == StringType) s"'${r.toString}'" else r.toString
Seq(s"$prettyLeft=$prettyRight")
case inn: IsNotNull => Seq(s"${inn.child.toString} is not null")
case p: Predicate => Seq(p.toString)
}
}
This gives the 4 elements List :
List('col1=1, 'col2 between 1 and 10, 'col2 between 190 and 200, 'col2 is not null)
For the second example :
select * from table where col1=1 and (col2 =2 or (col3 between 1 and 10 or col3 between 190 and 200)) and col4='xyz'
You'd get this output (List[String] with 5 elements) :
List('col1=1, 'col2=2, 'col3 between 1 and 10, 'col3 between 190 and 200, 'col4='xyz')
Additional note: If you want to print the attribute names without the starting quote, you can handle it by printing this instead of toString :
node.asInstanceOf[UnresolvedAttribute].name
I'm writing a console app in Symfony 3, but for some reason my query results are coming back with only 1 result in the array where I confirmed running it in MySQL and get several results back. Here is the relevant code:
$arr_id = array();
$em = $this->getContainer()->get('doctrine')->getManager();
$dql2 = 'SELECT r.productId as pid, COUNT(r.id) as cnt
FROM AppBundle:ReferralTrack r
WHERE r.productId in (:in)
GROUP BY r.productId
ORDER BY cnt DESC';
// $arr_id is populated prior to the next command and is, for example, [1,2,3,4,5]
$rt = $em->createQuery($dql2)
->setParameters(
array(
'in' => implode(',', $arr_id),
)
)
;
$traffic_count = $rt->getResult();
When I run the query in MySql, the exact same query shown by $rt->getSql() and replace the ? in the query with what is echoed out from implode(',', $arr_id), I get a similar result like this:
echo print_r( $traffic_count, 1);
---------------------------------
Array
(
[0] => Array
(
[pid] => 11234
[cnt] => 21
)
)
Here is the query I run in MySQL:
SELECT r0_.product_id AS pid, COUNT( r0_.id ) AS cnt
FROM referral_track r0_
WHERE r0_.product_id
IN ( 11234, 57, 58, 60, 61, 9677, 11216, 11217, 11239, 11296 )
GROUP BY r0_.product_id
ORDER BY cnt DESC
and it returns 7 results. What I have noticed is that getResult() does seem to always return the LAST record, that is what is shown the the array there. What is going on?
Try:
$rt = $em->createQuery($dql2)
->setParameters(
array(
'in' => $arr_id,
)
)
;
I am trying to get the mapping table associated ids.
mapping_table
id service_receiver_id service_provider_id
1 1 2
2 4 1
How can i write the doctrine query for retrieving 1 mapped to...
i need the results like,
associated_with
2
4
In my case i have using this query:
$qb->select('om', 'o', 'ot')
->from('Organization\Entity\OrgMapping', 'om')
->leftJoin('om.organization', 'o')
->where('om.organization = :hspId')
->setParameter('hspId', $hspId);
above query result only
//List of Associates that is Mapped Already
$organizations = $this->orgMappingRepository->listAssociatesByHSPId($hspId, $mapType, $filterBy, $searchBy, $pageNo, $paginationArr);
$mappedAssociates = array();
foreach ($organizations as $org) {
$mappedAssociates[$org->getServiceProvider()->getId()] = array(
'id' => $org->getServiceProvider()->getId(),
'name' => $org->getServiceProvider()->getName(),
'orgType' => $org->getServiceProvider()->getOrgType()->getName(),
'logo' => $org->getServiceProvider()->getLogo(),
'cityName' => $org->getServiceProvider()->getCity() ? $org->getServiceProvider()->getCity()->getName() : null,
'areaName' => $org->getServiceProvider()->getArea() ? $org->getServiceProvider()->getArea()->getName() : null,
'zipcode' => $org->getServiceProvider()->getZipcode(),
);
}
the result i am getting is :
id service_receiver_id service_provider_id
1 1 2
I need to obtain something like this:
However, I cannot know how to continue... now I have this:
In other words... I cannot know how to add tags and the corresponding transcripts, CDS, etc.
My code right now is the following one:
#!/usr/bin/perl
#use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;
my $panel = Bio::Graphics::Panel->new(
-length => 20000,
-width => 800
);
my $full_length = Bio::SeqFeature::Generic->new(
-start => 1,
-end => 20000,
);
$panel->add_track($full_length,
-key => "hola",
-glyph => 'arrow',
-tick => 2,
-fgcolor => 'black',
-double => 1,
);
my $track = $panel->add_track(
-glyph => 'generic',
-label => 1
);
my $track = $panel->add_track(
-glyph => 'generic',
-label => 1
);
$seq = "";
$seqlength = length($seq);
$count = 0;
while (<>) {
chomp;
next if /^\#/;
my #gff_data = split /\t+/;
next if ($gff_data[2] ne "gene");
my $feature = Bio::SeqFeature::Generic->new(
-display_name => $gff_data[8],
-score => $gff_data[5],
-start => $gff_data[3],
-end => $gff_data[4],
);
$track->add_feature($feature);
}
print $panel->png;
I've read as well the CPAN information but no clue... There is a lot of information for NCBI files but nothing for GFF...
My data:
313-9640000-9660000:19634:fwd maker gene 1978 7195 . + . ID=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10;Name=maker-313-9640000-9660000%253A19634%253Afwd-augustus-gene-0.10
313-9640000-9660000:19634:fwd maker mRNA 1978 7195 . + . ID=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1;Name=maker-313-9640000-9660000%253A19634%253Afwd-augustus-gene-0.10-mRNA-1;Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10
313-9640000-9660000:19634:fwd maker exon 1978 2207 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
313-9640000-9660000:19634:fwd maker exon 3081 3457 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
313-9640000-9660000:19634:fwd maker exon 3535 3700 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
Any help will be very wellcome.
use Bio::Graphics;
use Bio::Tools::GFF;
use Bio::SeqFeature::Generic;
$gfffile = shift;
my $gff = Bio::Tools::GFF->new(-file => $gfffile, -gff_version => 3);
while($feature = $gff->next_feature()) {
$tag = $feature->primary_tag;
push #{$hash{$tag}}, $feature;
}
$gff->close();
my $panel = Bio::Graphics::Panel->new(
-length => 20000,
-width => 800,
-key_style => 'between',
);
my $full_length = Bio::SeqFeature::Generic->new(
-start => 1,
-end => 20000,
);
$panel->add_track($full_length,
-key => "hola",
-glyph => 'arrow',
-tick => 2,
-fgcolor => 'black',
-double => 1,
);
my #colors = qw(cyan orange blue);
my $idx = 0;
for my $tag (sort keys %hash) {
my $features = $hash{$tag};
$panel->add_track($features,
-glyph => 'generic',
-bgcolor => $colors[$idx++ % #colors],
-fgcolor => 'black',
-font2color => 'red',
-key => "${tag}s",
-bump => +1,
-height => 8,
-label => 1,
-description => 1,
);
}
print $panel->png;
What you are showing in the first screen capture is likely from GBrowse, and the track labels (I think this is what you mean by 'tags') are defined in the configuration file. The feature label can be turned on/off by setting the 'label' and 'label_feat' attributes when you create the object. You will have to manually edit the file if you don't like those long strings set as the ID by MAKER.
You can change the appearance of each feature by choosing a different glyph. For example, you chose the 'generic' glyph, so what you get is a pretty generic looking box which just shows you the location of the feature. For nice looking transcripts, take a look at the 'processed_transcript' and 'decorated_transcript' glyphs.
There are also some problems with your code, such duplication of certain sections, but that may be from doing a copy and paste of the code.
I had the same problem than you. The thing is not very easy to explain. Finally I solved it and mi figure is pretty much similar at yours.
In my case I wanted to connect some encode data in the 5' UTR of several genes. And this encode data should be connected with dashed lines.
So I create a Bio::SeqFeature::Generic object and the information to plot inside are my encode regions, so this encode regions need to be sub_located inside :
my $splitlocation = Bio::Location::Split->new();
foreach $encode_regions ....{
$splitlocation->add_sub_Location(Bio::Location::Simple->new(-start=>$start,-end=>$end,- strand=>$strand,-splittype=>"join"));
}
$exones = new Bio::SeqFeature::Generic(
-primary_tag => 'Encode Regions',
-location=>$splitlocation
);